diff --git a/packages/database/src/databases/provider.ts b/packages/database/src/databases/provider.ts index 42dc26673..9e2d2bccf 100644 --- a/packages/database/src/databases/provider.ts +++ b/packages/database/src/databases/provider.ts @@ -733,19 +733,42 @@ export class ProviderDatabase limit = 1000, skip = 0, ): Promise { - const docs = await this.tables?.commitment - .find({ - $or: [ - { storedAtTimestamp: { $exists: false } }, - { - $expr: { $lt: ["$storedAtTimestamp", "$lastUpdatedTimestamp"] }, - }, - ], - }) - .sort({ _id: 1 }) // Consistent ordering is important for pagination - .skip(skip) - .limit(limit) - .lean(); + const docs = await this.tables?.commitment.aggregate([ + { + $match: { + $or: [ + { storedAtTimestamp: { $exists: false } }, + { + $expr: { + $lt: [ + { + $convert: { + input: "$storedAtTimestamp", + to: "date", + }, + }, + { + $convert: { + input: "$lastUpdatedTimestamp", + to: "date", + }, + }, + ], + }, + }, + ], + }, + }, + { + $sort: { _id: 1 }, + }, + { + $skip: skip, + }, + { + $limit: limit, + }, + ]); return docs || []; } @@ -790,20 +813,42 @@ export class ProviderDatabase limit = 1000, skip = 0, ): Promise { - const docs = await this.tables?.powcaptcha - .find({ - $or: [ - { storedAtTimestamp: { $exists: false } }, - { - $expr: { $lt: ["$storedAtTimestamp", "$lastUpdatedTimestamp"] }, - }, - ], - }) - .sort({ _id: 1 }) // Consistent ordering is important for pagination - .skip(skip) - .limit(limit) - .lean(); - + const docs = await this.tables?.powcaptcha.aggregate([ + { + $match: { + $or: [ + { storedAtTimestamp: { $exists: false } }, + { + $expr: { + $lt: [ + { + $convert: { + input: "$storedAtTimestamp", + to: "date", + }, + }, + { + $convert: { + input: "$lastUpdatedTimestamp", + to: "date", + }, + }, + ], + }, + }, + ], + }, + }, + { + $sort: { _id: 1 }, + }, + { + $skip: skip, + }, + { + $limit: limit, + }, + ]); return docs || []; } diff --git a/packages/provider/src/tasks/client/clientTasks.ts b/packages/provider/src/tasks/client/clientTasks.ts index 3b3e878ac..63b9ac0af 100644 --- a/packages/provider/src/tasks/client/clientTasks.ts +++ b/packages/provider/src/tasks/client/clientTasks.ts @@ -79,6 +79,7 @@ export class ClientTaskManager { // Process image commitments with cursor let processedCommitments = 0; + await this.processBatchesWithCursor( async (skip: number) => await this.providerDB.getUnstoredDappUserCommitments(