upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/sync/algorithms.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-16 15:26:55 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-16 15:26:55 +0000
commit7821b107190cc116a30a4c339f935bc16a1d5197 (patch)
treed9cc8f440304f383aa75689eb6c1f87cc75fd20d /src/sync/algorithms.rs
parent2164f075d441d7337b2b3d7ed85993fc69b8057e (diff)
proactive sync prep - some helper functions written but not enabled
Diffstat (limited to 'src/sync/algorithms.rs')
-rw-r--r--src/sync/algorithms.rs33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/sync/algorithms.rs b/src/sync/algorithms.rs
index 5b5b520..84248b1 100644
--- a/src/sync/algorithms.rs
+++ b/src/sync/algorithms.rs
@@ -11,7 +11,9 @@ use std::collections::{HashMap, HashSet};
11 11
12use nostr_sdk::prelude::*; 12use nostr_sdk::prelude::*;
13 13
14use super::{ConnectionStatus, PendingBatch, RelayState, SyncMethod}; 14use crate::sync::PendingItems;
15
16use super::{ConnectionStatus, PendingBatch, RelayState};
15 17
16// ============================================================================= 18// =============================================================================
17// Data Structures 19// Data Structures
@@ -36,10 +38,8 @@ pub struct RelaySyncNeeds {
36pub struct AddFilters { 38pub struct AddFilters {
37 /// The relay URL to add filters to 39 /// The relay URL to add filters to
38 pub relay_url: String, 40 pub relay_url: String,
39 /// Repos being synced in this action 41 /// pending items - repos and root events
40 pub repos: HashSet<String>, 42 pub items: PendingItems,
41 /// Root events being tracked in this action
42 pub root_events: HashSet<EventId>,
43 /// The actual filters to subscribe with 43 /// The actual filters to subscribe with
44 pub filters: Vec<Filter>, 44 pub filters: Vec<Filter>,
45} 45}
@@ -161,8 +161,10 @@ pub fn compute_actions(
161 161
162 actions.push(AddFilters { 162 actions.push(AddFilters {
163 relay_url: relay_url.clone(), 163 relay_url: relay_url.clone(),
164 repos: new_repos, 164 items: PendingItems {
165 root_events: new_events, 165 repos: new_repos,
166 root_events: new_events,
167 },
166 filters, 168 filters,
167 }); 169 });
168 } 170 }
@@ -175,6 +177,7 @@ pub fn compute_actions(
175mod tests { 177mod tests {
176 use super::*; 178 use super::*;
177 use crate::sync::RepoSyncNeeds as ModRepoSyncNeeds; 179 use crate::sync::RepoSyncNeeds as ModRepoSyncNeeds;
180 use crate::sync::SyncMethod;
178 181
179 // ========================================================================= 182 // =========================================================================
180 // derive_relay_targets tests 183 // derive_relay_targets tests
@@ -371,7 +374,7 @@ mod tests {
371 assert_eq!(actions.len(), 1); 374 assert_eq!(actions.len(), 1);
372 let action = &actions[0]; 375 let action = &actions[0];
373 assert_eq!(action.relay_url, "wss://relay1.com"); 376 assert_eq!(action.relay_url, "wss://relay1.com");
374 assert!(action.repos.contains("repo1")); 377 assert!(action.items.repos.contains("repo1"));
375 assert!(!action.filters.is_empty()); 378 assert!(!action.filters.is_empty());
376 } 379 }
377 380
@@ -528,10 +531,10 @@ mod tests {
528 assert_eq!(actions.len(), 1); 531 assert_eq!(actions.len(), 1);
529 let action = &actions[0]; 532 let action = &actions[0];
530 // Only repo3 should be in the action (repo1 pending, repo2 confirmed) 533 // Only repo3 should be in the action (repo1 pending, repo2 confirmed)
531 assert_eq!(action.repos.len(), 1); 534 assert_eq!(action.items.repos.len(), 1);
532 assert!(action.repos.contains("repo3")); 535 assert!(action.items.repos.contains("repo3"));
533 assert!(!action.repos.contains("repo1")); 536 assert!(!action.items.repos.contains("repo1"));
534 assert!(!action.repos.contains("repo2")); 537 assert!(!action.items.repos.contains("repo2"));
535 } 538 }
536 539
537 #[test] 540 #[test]
@@ -554,9 +557,9 @@ mod tests {
554 557
555 assert_eq!(actions.len(), 1); 558 assert_eq!(actions.len(), 1);
556 let action = &actions[0]; 559 let action = &actions[0];
557 assert!(action.repos.is_empty()); 560 assert!(action.items.repos.is_empty());
558 assert_eq!(action.root_events.len(), 1); 561 assert_eq!(action.items.root_events.len(), 1);
559 assert!(action.root_events.contains(&event_id)); 562 assert!(action.items.root_events.contains(&event_id));
560 // Should have 3 filters for the root event (e, E, q tags) 563 // Should have 3 filters for the root event (e, E, q tags)
561 assert_eq!(action.filters.len(), 3); 564 assert_eq!(action.filters.len(), 3);
562 } 565 }