Skip to content

Commit 7c2875a

Browse files
committed
Filter by group_id for populateChecksums.
1 parent 76846b7 commit 7c2875a

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

modules/module-mongodb-storage/src/storage/implementation/MongoCompactor.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { PowerSyncMongo } from './db.js';
66
import { BucketDataDocument, BucketDataKey, BucketStateDocument } from './models.js';
77
import { MongoSyncBucketStorage } from './MongoSyncBucketStorage.js';
88
import { cacheKey } from './OperationBatch.js';
9-
import { readSingleBatch } from './util.js';
109

1110
interface CurrentBucketState {
1211
/** Bucket name */
@@ -480,15 +479,25 @@ export class MongoCompactor {
480479
* Subset of compact, only populating checksums where relevant.
481480
*/
482481
async populateChecksums() {
483-
let lastId: BucketStateDocument['_id'] | null = null;
482+
// This is updated after each batch
483+
let lowerBound: BucketStateDocument['_id'] = {
484+
g: this.group_id,
485+
b: new mongo.MinKey() as any
486+
};
487+
// This is static
488+
const upperBound: BucketStateDocument['_id'] = {
489+
g: this.group_id,
490+
b: new mongo.MaxKey() as any
491+
};
484492
while (!this.signal?.aborted) {
485493
// By filtering buckets, we effectively make this "resumeable".
486-
let filter: mongo.Filter<BucketStateDocument> = {
494+
const filter: mongo.Filter<BucketStateDocument> = {
495+
_id: {
496+
$gt: lowerBound,
497+
$lt: upperBound
498+
},
487499
compacted_state: { $exists: false }
488500
};
489-
if (lastId) {
490-
filter._id = { $gt: lastId };
491-
}
492501

493502
const bucketsWithoutChecksums = await this.db.bucket_state
494503
.find(filter, {
@@ -511,7 +520,7 @@ export class MongoCompactor {
511520

512521
await this.updateChecksumsBatch(bucketsWithoutChecksums.map((b) => b._id.b));
513522

514-
lastId = bucketsWithoutChecksums[bucketsWithoutChecksums.length - 1]._id;
523+
lowerBound = bucketsWithoutChecksums[bucketsWithoutChecksums.length - 1]._id;
515524
}
516525
}
517526

0 commit comments

Comments
 (0)