From f75e1c59aacf5ce668fd327e4e3d827511661c2a Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 8 Jan 2026 00:50:54 +0000 Subject: chore: cargo fmt --- src/purgatory/sync/context.rs | 19 +++--------- src/purgatory/sync/functions.rs | 69 +++++++++++++++++++++-------------------- src/purgatory/sync/loop.rs | 5 ++- src/purgatory/sync/throttle.rs | 31 ++++++++---------- 4 files changed, 57 insertions(+), 67 deletions(-) (limited to 'src/purgatory/sync') diff --git a/src/purgatory/sync/context.rs b/src/purgatory/sync/context.rs index 2922f10..9e195c7 100644 --- a/src/purgatory/sync/context.rs +++ b/src/purgatory/sync/context.rs @@ -119,12 +119,8 @@ pub trait SyncContext: Send + Sync { /// /// # Returns /// List of OIDs that were successfully fetched - async fn fetch_oids( - &self, - repo_path: &Path, - url: &str, - oids: &[String], - ) -> Result>; + async fn fetch_oids(&self, repo_path: &Path, url: &str, oids: &[String]) + -> Result>; /// Process newly available git data. /// @@ -368,10 +364,7 @@ impl SyncContext for RealSyncContext { .cloned() .collect(); - debug!( - fetched_count = fetched.len(), - "Successfully fetched OIDs" - ); + debug!(fetched_count = fetched.len(), "Successfully fetched OIDs"); fetched } @@ -702,11 +695,7 @@ pub mod mock { } // Get OIDs this URL can provide - let provides = self - .url_provides_oids - .get(url) - .cloned() - .unwrap_or_default(); + let provides = self.url_provides_oids.get(url).cloned().unwrap_or_default(); // Find which requested OIDs this URL can provide let fetched: Vec = oids diff --git a/src/purgatory/sync/functions.rs b/src/purgatory/sync/functions.rs index bb7c0b9..370990e 100644 --- a/src/purgatory/sync/functions.rs +++ b/src/purgatory/sync/functions.rs @@ -32,15 +32,17 @@ use super::throttle::ThrottleManager; fn extract_domain(url: &str) -> Option { // Simple URL parsing for HTTP(S) URLs // Format: scheme://[user@]host[:port]/path - let url = url.strip_prefix("https://").or_else(|| url.strip_prefix("http://"))?; - + let url = url + .strip_prefix("https://") + .or_else(|| url.strip_prefix("http://"))?; + // Remove user info if present (e.g., "user@host" -> "host") let url = url.split('@').next_back()?; - + // Extract host (before first '/' or ':') let host = url.split('/').next()?; let host = host.split(':').next()?; - + if host.is_empty() { None } else { @@ -112,17 +114,17 @@ pub async fn sync_identifier_next_url( // 4. Collect clone URLs from announcements AND PR events in purgatory let our_domain = ctx.our_domain(); - + // Get clone URLs from repository announcements let announcement_urls: HashSet = repo_data .announcements .iter() .flat_map(|a| a.clone_urls.iter().cloned()) .collect(); - + // Get clone URLs from PR events in purgatory let pr_urls = ctx.collect_pr_clone_urls(identifier); - + // Merge and filter out our domain let all_urls: HashSet = announcement_urls .union(&pr_urls) @@ -151,11 +153,9 @@ pub async fn sync_identifier_next_url( match domain { Some(specific_domain) => { // Only look at URLs from this specific domain - urls_by_domain.get(specific_domain).and_then(|urls| { - urls.iter() - .find(|url| !tried_urls.contains(*url)) - .cloned() - }) + urls_by_domain + .get(specific_domain) + .and_then(|urls| urls.iter().find(|url| !tried_urls.contains(*url)).cloned()) } None => { // Try any non-throttled domain @@ -217,17 +217,17 @@ pub async fn get_throttled_domains_with_untried_urls( }; let our_domain = ctx.our_domain(); - + // Get clone URLs from repository announcements let announcement_urls: HashSet = repo_data .announcements .iter() .flat_map(|a| a.clone_urls.iter().cloned()) .collect(); - + // Get clone URLs from PR events in purgatory let pr_urls = ctx.collect_pr_clone_urls(identifier); - + // Merge and filter out our domain let all_urls: HashSet = announcement_urls .union(&pr_urls) @@ -766,9 +766,13 @@ mod tests { let mut tried_urls = HashSet::new(); tried_urls.insert("https://github.com/foo/bar.git".to_string()); - let throttled = - get_throttled_domains_with_untried_urls(&mock, "test-repo", &tried_urls, &throttle_manager) - .await; + let throttled = get_throttled_domains_with_untried_urls( + &mock, + "test-repo", + &tried_urls, + &throttle_manager, + ) + .await; // Should only include gitlab.com (throttled with untried URLs) // github.com is throttled but URL was tried @@ -885,11 +889,10 @@ mod tests { #[tokio::test] async fn test_collect_pr_clone_urls_returns_configured_urls() { // Test that MockSyncContext returns configured PR clone URLs - let mock = MockSyncContext::new() - .with_pr_clone_urls(&[ - "https://pr-server.com/fork.git", - "https://another-server.com/fork.git", - ]); + let mock = MockSyncContext::new().with_pr_clone_urls(&[ + "https://pr-server.com/fork.git", + "https://another-server.com/fork.git", + ]); let pr_urls = mock.collect_pr_clone_urls("test-repo"); @@ -945,7 +948,7 @@ mod tests { .with_urls(&["https://github.com/owner/repo.git"]) .with_pr_clone_urls(&[ "https://our-relay.com/fork.git", // Should be filtered - "https://external.com/fork.git", // Should be included + "https://external.com/fork.git", // Should be included ]) .with_our_domain("our-relay.com") .with_needed_oids(&["abc123"]) @@ -957,8 +960,7 @@ mod tests { // Collect all available URLs let mut available_urls = Vec::new(); while let Some(url) = - sync_identifier_next_url(&mock, "test-repo", None, &tried_urls, &throttle_manager) - .await + sync_identifier_next_url(&mock, "test-repo", None, &tried_urls, &throttle_manager).await { available_urls.push(url.clone()); tried_urls.insert(url); @@ -1006,16 +1008,17 @@ mod tests { let tried_urls = HashSet::new(); - let throttled = - get_throttled_domains_with_untried_urls(&mock, "test-repo", &tried_urls, &throttle_manager) - .await; + let throttled = get_throttled_domains_with_untried_urls( + &mock, + "test-repo", + &tried_urls, + &throttle_manager, + ) + .await; // Should include both throttled domains let domains: Vec<&str> = throttled.iter().map(|t| t.domain.as_str()).collect(); - assert!( - domains.contains(&"github.com"), - "Should include github.com" - ); + assert!(domains.contains(&"github.com"), "Should include github.com"); assert!( domains.contains(&"pr-server.com"), "Should include pr-server.com from PR clone URLs" diff --git a/src/purgatory/sync/loop.rs b/src/purgatory/sync/loop.rs index ebca766..92e0594 100644 --- a/src/purgatory/sync/loop.rs +++ b/src/purgatory/sync/loop.rs @@ -62,7 +62,10 @@ impl Purgatory { ctx: Arc, throttle_manager: Arc, ) -> JoinHandle<()> { - info!("Starting purgatory sync loop (interval: {:?})", SYNC_LOOP_INTERVAL); + info!( + "Starting purgatory sync loop (interval: {:?})", + SYNC_LOOP_INTERVAL + ); tokio::spawn(async move { let mut interval = tokio::time::interval(SYNC_LOOP_INTERVAL); diff --git a/src/purgatory/sync/throttle.rs b/src/purgatory/sync/throttle.rs index e6efe1f..ad6e8ea 100644 --- a/src/purgatory/sync/throttle.rs +++ b/src/purgatory/sync/throttle.rs @@ -316,15 +316,13 @@ impl ThrottleManager { } // Create new throttle - self.throttles - .entry(domain.to_string()) - .or_insert_with(|| { - Mutex::new(DomainThrottle::new( - domain.to_string(), - self.max_concurrent_per_domain, - self.max_per_minute_per_domain, - )) - }); + self.throttles.entry(domain.to_string()).or_insert_with(|| { + Mutex::new(DomainThrottle::new( + domain.to_string(), + self.max_concurrent_per_domain, + self.max_per_minute_per_domain, + )) + }); // Return the entry (we know it exists now) self.throttles.get(domain).unwrap() @@ -438,7 +436,9 @@ impl ThrottleManager { let domain = domain.to_string(); tokio::spawn(async move { - manager.process_queued_identifier(&domain, &identifier).await; + manager + .process_queued_identifier(&domain, &identifier) + .await; }); } } @@ -480,14 +480,9 @@ impl ThrottleManager { }; // Get next URL for this identifier on this specific domain - let url = sync_identifier_next_url( - ctx.as_ref(), - identifier, - Some(domain), - &tried_urls, - self, - ) - .await; + let url = + sync_identifier_next_url(ctx.as_ref(), identifier, Some(domain), &tried_urls, self) + .await; match url { Some(url) => { -- cgit v1.2.3