upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/purgatory/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/purgatory/mod.rs')
-rw-r--r--src/purgatory/mod.rs51
1 files changed, 41 insertions, 10 deletions
diff --git a/src/purgatory/mod.rs b/src/purgatory/mod.rs
index bb6ff54..9b370d2 100644
--- a/src/purgatory/mod.rs
+++ b/src/purgatory/mod.rs
@@ -16,8 +16,14 @@ pub mod persistence;
16pub mod sync; 16pub mod sync;
17mod types; 17mod types;
18 18
19pub use helpers::{can_apply_state, can_satisfy_state, diagnose_state_mismatch, extract_refs_from_state, get_unpushed_refs}; 19pub use helpers::{
20pub use types::{AnnouncementPurgatoryEntry, EventSource, PrPurgatoryEntry, RefPair, RefUpdate, StatePurgatoryEntry}; 20 can_apply_state, can_satisfy_state, diagnose_state_mismatch, extract_refs_from_state,
21 get_unpushed_refs,
22};
23pub use types::{
24 AnnouncementPurgatoryEntry, EventSource, PrPurgatoryEntry, RefPair, RefUpdate,
25 StatePurgatoryEntry,
26};
21 27
22use dashmap::DashMap; 28use dashmap::DashMap;
23use nostr_sdk::prelude::*; 29use nostr_sdk::prelude::*;
@@ -672,9 +678,15 @@ impl Purgatory {
672 /// 678 ///
673 /// # Returns 679 /// # Returns
674 /// The announcement entry if found, None otherwise 680 /// The announcement entry if found, None otherwise
675 pub fn find_announcement(&self, owner: &PublicKey, identifier: &str) -> Option<AnnouncementPurgatoryEntry> { 681 pub fn find_announcement(
682 &self,
683 owner: &PublicKey,
684 identifier: &str,
685 ) -> Option<AnnouncementPurgatoryEntry> {
676 let key = (*owner, identifier.to_string()); 686 let key = (*owner, identifier.to_string());
677 self.announcement_purgatory.get(&key).map(|entry| entry.clone()) 687 self.announcement_purgatory
688 .get(&key)
689 .map(|entry| entry.clone())
678 } 690 }
679 691
680 /// Get all announcements in purgatory for a given identifier. 692 /// Get all announcements in purgatory for a given identifier.
@@ -687,7 +699,10 @@ impl Purgatory {
687 /// 699 ///
688 /// # Returns 700 /// # Returns
689 /// Vector of announcement entries for this identifier 701 /// Vector of announcement entries for this identifier
690 pub fn get_announcements_by_identifier(&self, identifier: &str) -> Vec<AnnouncementPurgatoryEntry> { 702 pub fn get_announcements_by_identifier(
703 &self,
704 identifier: &str,
705 ) -> Vec<AnnouncementPurgatoryEntry> {
691 self.announcement_purgatory 706 self.announcement_purgatory
692 .iter() 707 .iter()
693 .filter(|entry| entry.key().1 == identifier) 708 .filter(|entry| entry.key().1 == identifier)
@@ -755,7 +770,12 @@ impl Purgatory {
755 /// * `owner` - The owner pubkey 770 /// * `owner` - The owner pubkey
756 /// * `identifier` - The repository identifier 771 /// * `identifier` - The repository identifier
757 /// * `duration` - Minimum duration to guarantee from now 772 /// * `duration` - Minimum duration to guarantee from now
758 pub fn extend_announcement_expiry(&self, owner: &PublicKey, identifier: &str, duration: Duration) { 773 pub fn extend_announcement_expiry(
774 &self,
775 owner: &PublicKey,
776 identifier: &str,
777 duration: Duration,
778 ) {
759 let key = (*owner, identifier.to_string()); 779 let key = (*owner, identifier.to_string());
760 780
761 // Collect revival info before taking a mutable borrow 781 // Collect revival info before taking a mutable borrow
@@ -977,16 +997,24 @@ impl Purgatory {
977 .map(|entry| { 997 .map(|entry| {
978 let key = entry.key(); 998 let key = entry.key();
979 let v = entry.value(); 999 let v = entry.value();
980 (key.0.clone(), key.1.clone(), v.repo_path.clone(), v.event.id, v.soft_expired) 1000 (
1001 key.0,
1002 key.1.clone(),
1003 v.repo_path.clone(),
1004 v.event.id,
1005 v.soft_expired,
1006 )
981 }) 1007 })
982 .collect(); 1008 .collect();
983 1009
984 let mut announcement_removed = 0; 1010 let mut announcement_removed = 0;
985 for (owner, identifier, repo_path, event_id, already_soft_expired) in expired_announcements { 1011 for (owner, identifier, repo_path, event_id, already_soft_expired) in expired_announcements
1012 {
986 if already_soft_expired { 1013 if already_soft_expired {
987 // Phase 2: fully remove 1014 // Phase 2: fully remove
988 self.mark_expired(event_id); 1015 self.mark_expired(event_id);
989 self.announcement_purgatory.remove(&(owner.clone(), identifier.clone())); 1016 self.announcement_purgatory
1017 .remove(&(owner, identifier.clone()));
990 announcement_removed += 1; 1018 announcement_removed += 1;
991 tracing::info!( 1019 tracing::info!(
992 owner = %owner, 1020 owner = %owner,
@@ -1026,7 +1054,10 @@ impl Purgatory {
1026 1054
1027 if repo_gone { 1055 if repo_gone {
1028 // Mark soft_expired and extend expiry 1056 // Mark soft_expired and extend expiry
1029 if let Some(mut entry) = self.announcement_purgatory.get_mut(&(owner.clone(), identifier.clone())) { 1057 if let Some(mut entry) = self
1058 .announcement_purgatory
1059 .get_mut(&(owner, identifier.clone()))
1060 {
1030 entry.soft_expired = true; 1061 entry.soft_expired = true;
1031 entry.expires_at = now + SOFT_EXPIRY_EXTENDED; 1062 entry.expires_at = now + SOFT_EXPIRY_EXTENDED;
1032 } 1063 }