upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/sync/rejected_index.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-01-09 19:58:41 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-01-09 19:58:41 +0000
commitb28a356cb41077ccee12a9c52f4ef2054e76cac6 (patch)
tree2a0867f1ab0216e86efa062aef90b2b8077e6fb9 /src/sync/rejected_index.rs
parent6dd9fcd5392891b0ddb7894e2c5cb40450eae00e (diff)
chore: cargo fmt
Diffstat (limited to 'src/sync/rejected_index.rs')
-rw-r--r--src/sync/rejected_index.rs57
1 files changed, 15 insertions, 42 deletions
diff --git a/src/sync/rejected_index.rs b/src/sync/rejected_index.rs
index a9d7a4d..403792a 100644
--- a/src/sync/rejected_index.rs
+++ b/src/sync/rejected_index.rs
@@ -190,9 +190,7 @@ impl HotCache {
190 let now = Instant::now(); 190 let now = Instant::now();
191 let initial_count = entries.len(); 191 let initial_count = entries.len();
192 192
193 entries.retain(|_, entry| { 193 entries.retain(|_, entry| now.duration_since(entry.cached_at) < self.expiry_duration);
194 now.duration_since(entry.cached_at) < self.expiry_duration
195 });
196 194
197 initial_count - entries.len() 195 initial_count - entries.len()
198 } 196 }
@@ -284,9 +282,7 @@ impl ColdIndex {
284 let now = Instant::now(); 282 let now = Instant::now();
285 let initial_count = entries.len(); 283 let initial_count = entries.len();
286 284
287 entries.retain(|_, entry| { 285 entries.retain(|_, entry| now.duration_since(entry.rejected_at) < self.expiry_duration);
288 now.duration_since(entry.rejected_at) < self.expiry_duration
289 });
290 286
291 initial_count - entries.len() 287 initial_count - entries.len()
292 } 288 }
@@ -389,12 +385,8 @@ impl RejectedEventsIndex {
389 reason: RejectionReason, 385 reason: RejectionReason,
390 ) { 386 ) {
391 // Add to hot cache (full event) 387 // Add to hot cache (full event)
392 self.hot_cache.add( 388 self.hot_cache
393 event.clone(), 389 .add(event.clone(), pubkey, identifier.clone(), reason);
394 pubkey,
395 identifier.clone(),
396 reason,
397 );
398 390
399 // Add to cold index (metadata only) 391 // Add to cold index (metadata only)
400 self.cold_index.add(event.id, pubkey, identifier, reason); 392 self.cold_index.add(event.id, pubkey, identifier, reason);
@@ -419,12 +411,8 @@ impl RejectedEventsIndex {
419 reason: RejectionReason, 411 reason: RejectionReason,
420 ) { 412 ) {
421 // Add to hot cache (full event) 413 // Add to hot cache (full event)
422 self.hot_cache.add( 414 self.hot_cache
423 event.clone(), 415 .add(event.clone(), pubkey, identifier.clone(), reason);
424 pubkey,
425 identifier.clone(),
426 reason,
427 );
428 416
429 // Add to cold index (metadata only) 417 // Add to cold index (metadata only)
430 self.cold_index.add(event.id, pubkey, identifier, reason); 418 self.cold_index.add(event.id, pubkey, identifier, reason);
@@ -608,8 +596,7 @@ mod tests {
608 596
609 async fn create_test_event() -> Event { 597 async fn create_test_event() -> Event {
610 let keys = Keys::generate(); 598 let keys = Keys::generate();
611 let unsigned = nostr_sdk::EventBuilder::text_note("test") 599 let unsigned = nostr_sdk::EventBuilder::text_note("test").build(keys.public_key());
612 .build(keys.public_key());
613 keys.sign_event(unsigned).await.unwrap() 600 keys.sign_event(unsigned).await.unwrap()
614 } 601 }
615 602
@@ -695,10 +682,7 @@ mod tests {
695 682
696 #[tokio::test] 683 #[tokio::test]
697 async fn test_two_tier_index_add_and_contains() { 684 async fn test_two_tier_index_add_and_contains() {
698 let index = RejectedEventsIndex::new( 685 let index = RejectedEventsIndex::new(Duration::from_secs(120), Duration::from_secs(604800));
699 Duration::from_secs(120),
700 Duration::from_secs(604800),
701 );
702 let event = create_test_event().await; 686 let event = create_test_event().await;
703 687
704 index.add_announcement( 688 index.add_announcement(
@@ -715,10 +699,7 @@ mod tests {
715 699
716 #[tokio::test] 700 #[tokio::test]
717 async fn test_invalidate_and_get_events() { 701 async fn test_invalidate_and_get_events() {
718 let index = RejectedEventsIndex::new( 702 let index = RejectedEventsIndex::new(Duration::from_secs(120), Duration::from_secs(604800));
719 Duration::from_secs(120),
720 Duration::from_secs(604800),
721 );
722 let event = create_test_event().await; 703 let event = create_test_event().await;
723 let pubkey = event.pubkey; 704 let pubkey = event.pubkey;
724 let identifier = "test-repo".to_string(); 705 let identifier = "test-repo".to_string();
@@ -773,10 +754,8 @@ mod tests {
773 754
774 #[tokio::test] 755 #[tokio::test]
775 async fn test_hot_cache_miss_after_expiry() { 756 async fn test_hot_cache_miss_after_expiry() {
776 let index = RejectedEventsIndex::new( 757 let index =
777 Duration::from_millis(50), 758 RejectedEventsIndex::new(Duration::from_millis(50), Duration::from_secs(604800));
778 Duration::from_secs(604800),
779 );
780 let event = create_test_event().await; 759 let event = create_test_event().await;
781 let pubkey = event.pubkey; 760 let pubkey = event.pubkey;
782 let identifier = "test-repo".to_string(); 761 let identifier = "test-repo".to_string();
@@ -801,20 +780,15 @@ mod tests {
801 780
802 #[tokio::test] 781 #[tokio::test]
803 async fn test_multiple_maintainer_repos() { 782 async fn test_multiple_maintainer_repos() {
804 let index = RejectedEventsIndex::new( 783 let index = RejectedEventsIndex::new(Duration::from_secs(120), Duration::from_secs(604800));
805 Duration::from_secs(120),
806 Duration::from_secs(604800),
807 );
808 784
809 let keys1 = Keys::generate(); 785 let keys1 = Keys::generate();
810 let keys2 = Keys::generate(); 786 let keys2 = Keys::generate();
811 787
812 let unsigned1 = nostr_sdk::EventBuilder::text_note("test1") 788 let unsigned1 = nostr_sdk::EventBuilder::text_note("test1").build(keys1.public_key());
813 .build(keys1.public_key());
814 let event1 = keys1.sign_event(unsigned1).await.unwrap(); 789 let event1 = keys1.sign_event(unsigned1).await.unwrap();
815 790
816 let unsigned2 = nostr_sdk::EventBuilder::text_note("test2") 791 let unsigned2 = nostr_sdk::EventBuilder::text_note("test2").build(keys2.public_key());
817 .build(keys2.public_key());
818 let event2 = keys2.sign_event(unsigned2).await.unwrap(); 792 let event2 = keys2.sign_event(unsigned2).await.unwrap();
819 793
820 // Add two different maintainer repos 794 // Add two different maintainer repos
@@ -836,8 +810,7 @@ mod tests {
836 assert_eq!(index.cold_index_len(), 2); 810 assert_eq!(index.cold_index_len(), 2);
837 811
838 // Invalidate only first maintainer 812 // Invalidate only first maintainer
839 let (removed, hot_events) = 813 let (removed, hot_events) = index.invalidate_and_get_events(&event1.pubkey, "repo1");
840 index.invalidate_and_get_events(&event1.pubkey, "repo1");
841 814
842 assert_eq!(removed, 1); 815 assert_eq!(removed, 1);
843 assert_eq!(hot_events.len(), 1); 816 assert_eq!(hot_events.len(), 1);