From 44c6d801521ec1335c86826c11a4542bf43d567e Mon Sep 17 00:00:00 2001 From: dawn <90008@gaze.systems> Date: Fri, 17 Apr 2026 23:34:10 +0300 Subject: [PATCH] [firehose,lib,api] add is_source_running, shortcircuit requestCrawl if source is already running to prevent task restart --- src/api/xrpc/request_crawl.rs | 5 +++++ src/control/firehose.rs | 15 ++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/api/xrpc/request_crawl.rs b/src/api/xrpc/request_crawl.rs index 344a1fc..0957c29 100644 --- a/src/api/xrpc/request_crawl.rs +++ b/src/api/xrpc/request_crawl.rs @@ -24,6 +24,11 @@ pub async fn handle( }); } + // if this host is already running, everything is already ok + if hydrant.firehose.is_source_running(&url) { + return Ok(StatusCode::OK); + } + // enforce daily new pds limit on unknown hosts if !hydrant.firehose.is_source_known(&url) { let (allowed, to_persist) = hydrant.state.pds_daily_limit.try_increment(); diff --git a/src/control/firehose.rs b/src/control/firehose.rs index f39b700..af476d0 100644 --- a/src/control/firehose.rs +++ b/src/control/firehose.rs @@ -151,22 +151,27 @@ impl FirehoseHandle { *self.state.firehose_enabled.borrow() } - /// returns `true` if this URL is already a known firehose source — either currently - /// running or persisted (e.g. the host is offline but was previously added). + /// returns `true` if this URL is already a known firehose source. + /// either currently running or persisted (e.g. the host is offline but was previously added). pub fn is_source_known(&self, url: &Url) -> bool { self.known_sources.contains_sync(url) } + /// return `true` if this source has a running firehose task (eg. its not offline). + pub fn is_source_running(&self, url: &Url) -> bool { + self.tasks.contains_sync(url) + } + /// list all currently active firehose sources. pub async fn list_sources(&self) -> Vec { - let mut out = Vec::new(); + let mut out = Vec::with_capacity(self.tasks.capacity()); self.tasks - .any_async(|url, handle| { + .iter_async(|url, handle| { out.push(FirehoseSourceInfo { url: url.clone(), is_pds: handle.is_pds, }); - false + true }) .await; out -- 2.51.2