11use alloc:: { boxed:: Box , collections:: btree_map:: BTreeMap , rc:: Rc , string:: String , vec:: Vec } ;
22use core:: {
33 cell:: RefCell ,
4+ cmp:: min,
45 hash:: { BuildHasher , Hash } ,
56} ;
67use rustc_hash:: FxBuildHasher ;
78use serde:: Serialize ;
89use sqlite_nostd:: ResultCode ;
910
1011use crate :: {
11- sync:: { storage_adapter:: StorageAdapter , subscriptions:: LocallyTrackedSubscription } ,
12+ sync:: {
13+ checkpoint:: OwnedBucketChecksum , storage_adapter:: StorageAdapter ,
14+ subscriptions:: LocallyTrackedSubscription ,
15+ } ,
1216 util:: JsonString ,
1317} ;
1418
@@ -37,7 +41,7 @@ pub struct DownloadSyncStatus {
3741 /// When a download is active (that is, a `checkpoint` or `checkpoint_diff` line has been
3842 /// received), information about how far the download has progressed.
3943 pub downloading : Option < SyncDownloadProgress > ,
40- pub streams : Vec < ActiveStreamSubscription > ,
44+ pub streams : Option < Vec < ActiveStreamSubscription > > ,
4145}
4246
4347impl DownloadSyncStatus {
@@ -78,7 +82,7 @@ impl DownloadSyncStatus {
7882 self . mark_connected ( ) ;
7983
8084 self . downloading = Some ( progress) ;
81- self . streams = subscriptions;
85+ self . streams = Some ( subscriptions) ;
8286 }
8387
8488 /// Increments [SyncDownloadProgress] progress for the given [DataLine].
@@ -122,7 +126,7 @@ impl Default for DownloadSyncStatus {
122126 connecting : false ,
123127 downloading : None ,
124128 priority_status : Vec :: new ( ) ,
125- streams : Vec :: new ( ) ,
129+ streams : None ,
126130 }
127131 }
128132}
@@ -140,6 +144,10 @@ impl SyncStatusContainer {
140144 }
141145 }
142146
147+ pub fn inner ( & self ) -> & Rc < RefCell < DownloadSyncStatus > > {
148+ & self . status
149+ }
150+
143151 /// Invokes a function to update the sync status, then emits an [Instruction::UpdateSyncStatus]
144152 /// if the function did indeed change the status.
145153 pub fn update < F : FnOnce ( & mut DownloadSyncStatus ) -> ( ) > (
@@ -265,9 +273,12 @@ impl SyncDownloadProgress {
265273
266274#[ derive( Serialize , Hash ) ]
267275pub struct ActiveStreamSubscription {
276+ #[ serde( skip) ]
277+ pub id : i64 ,
268278 pub name : String ,
269279 pub parameters : Option < Box < JsonString > > ,
270280 pub associated_buckets : Vec < String > ,
281+ pub priority : Option < BucketPriority > ,
271282 pub active : bool ,
272283 pub is_default : bool ,
273284 pub expires_at : Option < Timestamp > ,
@@ -277,13 +288,30 @@ pub struct ActiveStreamSubscription {
277288impl ActiveStreamSubscription {
278289 pub fn from_local ( local : & LocallyTrackedSubscription ) -> Self {
279290 Self {
291+ id : local. id ,
280292 name : local. stream_name . clone ( ) ,
281293 parameters : local. local_params . clone ( ) ,
282294 is_default : local. is_default ,
295+ priority : None ,
283296 associated_buckets : Vec :: new ( ) ,
284297 active : local. active ,
285298 expires_at : local. expires_at . clone ( ) . map ( |e| Timestamp ( e) ) ,
286299 last_synced_at : local. last_synced_at . map ( |e| Timestamp ( e) ) ,
287300 }
288301 }
302+
303+ pub fn mark_associated_with_bucket ( & mut self , bucket : & OwnedBucketChecksum ) {
304+ self . associated_buckets . push ( bucket. bucket . clone ( ) ) ;
305+ self . priority = Some ( match self . priority {
306+ None => bucket. priority ,
307+ Some ( prio) => min ( prio, bucket. priority ) ,
308+ } ) ;
309+ }
310+
311+ pub fn is_in_priority ( & self , prio : Option < BucketPriority > ) -> bool {
312+ match prio {
313+ None => true ,
314+ Some ( prio) => self . priority >= Some ( prio) ,
315+ }
316+ }
289317}
0 commit comments