@@ -18,7 +18,9 @@ import {
18
18
ReplicationCheckpoint ,
19
19
storage ,
20
20
utils ,
21
- WatchWriteCheckpointOptions
21
+ WatchWriteCheckpointOptions ,
22
+ CHECKPOINT_INVALIDATE_ALL ,
23
+ deserializeParameterLookup
22
24
} from '@powersync/service-core' ;
23
25
import { SqliteJsonRow , SqliteJsonValue , SqlSyncRules } from '@powersync/service-sync-rules' ;
24
26
import * as bson from 'bson' ;
@@ -39,6 +41,7 @@ import { MongoBucketBatch } from './MongoBucketBatch.js';
39
41
import { MongoCompactor } from './MongoCompactor.js' ;
40
42
import { MongoWriteCheckpointAPI } from './MongoWriteCheckpointAPI.js' ;
41
43
import { idPrefixFilter , mapOpEntry , readSingleBatch } from './util.js' ;
44
+ import { JSONBig } from '@powersync/service-jsonbig' ;
42
45
43
46
export class MongoSyncBucketStorage
44
47
extends BaseObserver < storage . SyncRulesBucketStorageListener >
@@ -795,12 +798,7 @@ export class MongoSyncBucketStorage
795
798
796
799
const updates : CheckpointChanges =
797
800
lastCheckpoint == null
798
- ? {
799
- invalidateDataBuckets : true ,
800
- invalidateParameterBuckets : true ,
801
- updatedDataBuckets : [ ] ,
802
- updatedParameterBucketDefinitions : [ ]
803
- }
801
+ ? CHECKPOINT_INVALIDATE_ALL
804
802
: await this . getCheckpointChanges ( {
805
803
lastCheckpoint : lastCheckpoint ,
806
804
nextCheckpoint : checkpoint
@@ -877,7 +875,7 @@ export class MongoSyncBucketStorage
877
875
// Or we could store updated buckets in a separate collection, and query those.
878
876
// For now, we ignore this optimization
879
877
880
- // const dataBuckets = await this.db.bucket_data
878
+ // const dataBucketDocuments = await this.db.bucket_data
881
879
// .find(
882
880
// {
883
881
// '_id.g': this.group_id,
@@ -894,6 +892,14 @@ export class MongoSyncBucketStorage
894
892
// )
895
893
// .toArray();
896
894
895
+ // const buckets = dataBucketDocuments.map((doc) => doc._id.b);
896
+ // const invalidateDataBuckets = buckets.length > 1000;
897
+
898
+ // return {
899
+ // invalidateDataBuckets: invalidateDataBuckets,
900
+ // updatedDataBuckets: invalidateDataBuckets ? [] : buckets
901
+ // };
902
+
897
903
return {
898
904
invalidateDataBuckets : true ,
899
905
updatedDataBuckets : [ ]
@@ -902,7 +908,7 @@ export class MongoSyncBucketStorage
902
908
903
909
private async getParameterBucketChanges (
904
910
options : GetCheckpointChangesOptions
905
- ) : Promise < Pick < CheckpointChanges , 'updatedParameterBucketDefinitions ' | 'invalidateParameterBuckets' > > {
911
+ ) : Promise < Pick < CheckpointChanges , 'updatedParameterLookups ' | 'invalidateParameterBuckets' > > {
906
912
// TODO: limit max query running time
907
913
const parameterUpdates = await this . db . bucket_parameters
908
914
. find (
@@ -924,9 +930,9 @@ export class MongoSyncBucketStorage
924
930
925
931
return {
926
932
invalidateParameterBuckets : invalidateParameterUpdates ,
927
- updatedParameterBucketDefinitions : invalidateParameterUpdates
928
- ? [ ]
929
- : [ ... new Set < string > ( parameterUpdates . map ( ( p ) => getLookupBucketDefinitionName ( p . lookup ) ) ) ]
933
+ updatedParameterLookups : invalidateParameterUpdates
934
+ ? new Set < string > ( )
935
+ : new Set < string > ( parameterUpdates . map ( ( p ) => JSONBig . stringify ( deserializeParameterLookup ( p . lookup ) ) ) )
930
936
} ;
931
937
}
932
938
@@ -937,7 +943,7 @@ export class MongoSyncBucketStorage
937
943
max : 50 ,
938
944
maxSize : 10 * 1024 * 1024 ,
939
945
sizeCalculation : ( value : CheckpointChanges ) => {
940
- return 100 + value . updatedParameterBucketDefinitions . reduce < number > ( ( a , b ) => a + b . length , 0 ) ;
946
+ return 100 + [ ... value . updatedParameterLookups ] . reduce < number > ( ( a , b ) => a + b . length , 0 ) ;
941
947
} ,
942
948
fetchMethod : async ( _key , _staleValue , options ) => {
943
949
return this . getCheckpointChangesInternal ( options . context . options ) ;
@@ -966,7 +972,7 @@ export class MongoSyncBucketStorage
966
972
invalidateDataBuckets : true ,
967
973
updatedDataBuckets : [ ] ,
968
974
invalidateParameterBuckets : false ,
969
- updatedParameterBucketDefinitions : [ ]
975
+ updatedParameterLookups : new Set < string > ( )
970
976
} ;
971
977
}
972
978
const key = `${ options . lastCheckpoint } _${ options . nextCheckpoint } ` ;
0 commit comments