diff options
Diffstat (limited to 'src/purgatory/sync/context.rs')
| -rw-r--r-- | src/purgatory/sync/context.rs | 116 |
1 files changed, 0 insertions, 116 deletions
diff --git a/src/purgatory/sync/context.rs b/src/purgatory/sync/context.rs index 4dbb402..3568e89 100644 --- a/src/purgatory/sync/context.rs +++ b/src/purgatory/sync/context.rs | |||
| @@ -193,7 +193,6 @@ use crate::nostr::builder::SharedDatabase; | |||
| 193 | use crate::nostr::events::RepositoryState; | 193 | use crate::nostr::events::RepositoryState; |
| 194 | use crate::purgatory::Purgatory; | 194 | use crate::purgatory::Purgatory; |
| 195 | use crate::sync::naughty_list::NaughtyListTracker; | 195 | use crate::sync::naughty_list::NaughtyListTracker; |
| 196 | use crate::sync::RepoSyncIndex; | ||
| 197 | 196 | ||
| 198 | use super::functions::extract_domain; | 197 | use super::functions::extract_domain; |
| 199 | 198 | ||
| @@ -222,13 +221,6 @@ pub struct RealSyncContext { | |||
| 222 | 221 | ||
| 223 | /// Naughty list tracker for git remote domains with persistent errors | 222 | /// Naughty list tracker for git remote domains with persistent errors |
| 224 | git_naughty_list: Arc<NaughtyListTracker>, | 223 | git_naughty_list: Arc<NaughtyListTracker>, |
| 225 | |||
| 226 | /// Optional repo sync index for upgrading sync level on promotion | ||
| 227 | repo_sync_index: Option<RepoSyncIndex>, | ||
| 228 | |||
| 229 | /// Optional sender for AddFilters actions to SyncManager. | ||
| 230 | /// Used after announcement promotion to trigger PR event subscription on connected relays. | ||
| 231 | sync_action_tx: Option<tokio::sync::mpsc::Sender<crate::sync::AddFilters>>, | ||
| 232 | } | 224 | } |
| 233 | 225 | ||
| 234 | impl RealSyncContext { | 226 | impl RealSyncContext { |
| @@ -241,9 +233,6 @@ impl RealSyncContext { | |||
| 241 | /// * `our_domain` - Our domain to exclude from clone URLs | 233 | /// * `our_domain` - Our domain to exclude from clone URLs |
| 242 | /// * `local_relay` - Local relay for WebSocket notifications | 234 | /// * `local_relay` - Local relay for WebSocket notifications |
| 243 | /// * `git_naughty_list` - Naughty list tracker for git remote domains | 235 | /// * `git_naughty_list` - Naughty list tracker for git remote domains |
| 244 | /// * `repo_sync_index` - Optional repo sync index for upgrading sync level on promotion | ||
| 245 | /// * `sync_action_tx` - Optional sender for triggering filter recomputation after promotion | ||
| 246 | #[allow(clippy::too_many_arguments)] | ||
| 247 | pub fn new( | 236 | pub fn new( |
| 248 | purgatory: Arc<Purgatory>, | 237 | purgatory: Arc<Purgatory>, |
| 249 | database: SharedDatabase, | 238 | database: SharedDatabase, |
| @@ -251,8 +240,6 @@ impl RealSyncContext { | |||
| 251 | our_domain: Option<String>, | 240 | our_domain: Option<String>, |
| 252 | local_relay: Option<LocalRelay>, | 241 | local_relay: Option<LocalRelay>, |
| 253 | git_naughty_list: Arc<NaughtyListTracker>, | 242 | git_naughty_list: Arc<NaughtyListTracker>, |
| 254 | repo_sync_index: Option<RepoSyncIndex>, | ||
| 255 | sync_action_tx: Option<tokio::sync::mpsc::Sender<crate::sync::AddFilters>>, | ||
| 256 | ) -> Self { | 243 | ) -> Self { |
| 257 | Self { | 244 | Self { |
| 258 | purgatory, | 245 | purgatory, |
| @@ -261,23 +248,9 @@ impl RealSyncContext { | |||
| 261 | our_domain_value: our_domain, | 248 | our_domain_value: our_domain, |
| 262 | local_relay, | 249 | local_relay, |
| 263 | git_naughty_list, | 250 | git_naughty_list, |
| 264 | repo_sync_index, | ||
| 265 | sync_action_tx, | ||
| 266 | } | 251 | } |
| 267 | } | 252 | } |
| 268 | 253 | ||
| 269 | /// Set the sync action sender for triggering filter recomputation after announcement promotion. | ||
| 270 | /// | ||
| 271 | /// When an announcement is promoted from purgatory to Full sync level, the SyncManager | ||
| 272 | /// needs to subscribe to PR events for that repo on all connected relays. This sender | ||
| 273 | /// is used to trigger that subscription. | ||
| 274 | pub fn set_sync_action_tx( | ||
| 275 | &mut self, | ||
| 276 | tx: tokio::sync::mpsc::Sender<crate::sync::AddFilters>, | ||
| 277 | ) { | ||
| 278 | self.sync_action_tx = Some(tx); | ||
| 279 | } | ||
| 280 | |||
| 281 | /// Get reference to the git naughty list tracker | 254 | /// Get reference to the git naughty list tracker |
| 282 | pub fn git_naughty_list(&self) -> &Arc<NaughtyListTracker> { | 255 | pub fn git_naughty_list(&self) -> &Arc<NaughtyListTracker> { |
| 283 | &self.git_naughty_list | 256 | &self.git_naughty_list |
| @@ -509,98 +482,9 @@ impl SyncContext for RealSyncContext { | |||
| 509 | self.local_relay.as_ref(), | 482 | self.local_relay.as_ref(), |
| 510 | &self.purgatory, | 483 | &self.purgatory, |
| 511 | &self.git_data_path, | 484 | &self.git_data_path, |
| 512 | self.repo_sync_index.clone(), | ||
| 513 | ) | 485 | ) |
| 514 | .await?; | 486 | .await?; |
| 515 | 487 | ||
| 516 | // If announcements were promoted (now Full sync level), notify SyncManager to | ||
| 517 | // recompute filters so PR event subscriptions are created on connected relays. | ||
| 518 | if result.announcements_released > 0 { | ||
| 519 | if let (Some(ref tx), Some(ref repo_sync_index)) = | ||
| 520 | (&self.sync_action_tx, &self.repo_sync_index) | ||
| 521 | { | ||
| 522 | let index = repo_sync_index.read().await; | ||
| 523 | for (repo_id, needs) in index.iter() { | ||
| 524 | if needs.sync_level == crate::sync::SyncLevel::Full | ||
| 525 | && !needs.root_events.is_empty() | ||
| 526 | { | ||
| 527 | // Send AddFilters for Full repos with root events | ||
| 528 | for relay_url in &needs.relays { | ||
| 529 | if let Some(ref domain) = self.our_domain_value { | ||
| 530 | if relay_url.contains(domain.as_str()) { | ||
| 531 | continue; | ||
| 532 | } | ||
| 533 | } | ||
| 534 | let full_repos: std::collections::HashSet<String> = | ||
| 535 | std::iter::once(repo_id.clone()).collect(); | ||
| 536 | let filters = | ||
| 537 | crate::sync::filters::build_sync_level_aware_filters( | ||
| 538 | &full_repos, | ||
| 539 | &std::collections::HashSet::new(), | ||
| 540 | &needs.root_events, | ||
| 541 | None, | ||
| 542 | ); | ||
| 543 | let action = crate::sync::AddFilters { | ||
| 544 | relay_url: relay_url.clone(), | ||
| 545 | items: crate::sync::PendingItems { | ||
| 546 | repos: full_repos.clone(), | ||
| 547 | root_events: needs.root_events.clone(), | ||
| 548 | }, | ||
| 549 | filters, | ||
| 550 | }; | ||
| 551 | if let Err(e) = tx.send(action).await { | ||
| 552 | debug!( | ||
| 553 | relay = %relay_url, | ||
| 554 | error = %e, | ||
| 555 | "Failed to send AddFilters after announcement promotion" | ||
| 556 | ); | ||
| 557 | } else { | ||
| 558 | debug!( | ||
| 559 | relay = %relay_url, | ||
| 560 | repo_id = %repo_id, | ||
| 561 | "Sent AddFilters to SyncManager after announcement promotion" | ||
| 562 | ); | ||
| 563 | } | ||
| 564 | } | ||
| 565 | } else if needs.sync_level == crate::sync::SyncLevel::Full { | ||
| 566 | // Even without root_events, send empty repo filter to ensure | ||
| 567 | // Layer 2 subscriptions (PR events) are set up | ||
| 568 | for relay_url in &needs.relays { | ||
| 569 | if let Some(ref domain) = self.our_domain_value { | ||
| 570 | if relay_url.contains(domain.as_str()) { | ||
| 571 | continue; | ||
| 572 | } | ||
| 573 | } | ||
| 574 | let full_repos: std::collections::HashSet<String> = | ||
| 575 | std::iter::once(repo_id.clone()).collect(); | ||
| 576 | let filters = | ||
| 577 | crate::sync::filters::build_sync_level_aware_filters( | ||
| 578 | &full_repos, | ||
| 579 | &std::collections::HashSet::new(), | ||
| 580 | &std::collections::HashSet::new(), | ||
| 581 | None, | ||
| 582 | ); | ||
| 583 | let action = crate::sync::AddFilters { | ||
| 584 | relay_url: relay_url.clone(), | ||
| 585 | items: crate::sync::PendingItems { | ||
| 586 | repos: full_repos.clone(), | ||
| 587 | root_events: std::collections::HashSet::new(), | ||
| 588 | }, | ||
| 589 | filters, | ||
| 590 | }; | ||
| 591 | if let Err(e) = tx.send(action).await { | ||
| 592 | debug!( | ||
| 593 | relay = %relay_url, | ||
| 594 | error = %e, | ||
| 595 | "Failed to send AddFilters (no root_events) after announcement promotion" | ||
| 596 | ); | ||
| 597 | } | ||
| 598 | } | ||
| 599 | } | ||
| 600 | } | ||
| 601 | } | ||
| 602 | } | ||
| 603 | |||
| 604 | // Convert from git::sync::ProcessResult to our ProcessResult | 488 | // Convert from git::sync::ProcessResult to our ProcessResult |
| 605 | Ok(ProcessResult { | 489 | Ok(ProcessResult { |
| 606 | states_released: result.states_released, | 490 | states_released: result.states_released, |