Skip to content

Commit aec79f0

Browse files
committed
Update query to get unstored commitments
1 parent 6bff959 commit aec79f0

File tree

2 files changed

+73
-27
lines changed

2 files changed

+73
-27
lines changed

packages/database/src/databases/provider.ts

Lines changed: 72 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -733,19 +733,42 @@ export class ProviderDatabase
733733
limit = 1000,
734734
skip = 0,
735735
): Promise<UserCommitmentRecord[]> {
736-
const docs = await this.tables?.commitment
737-
.find({
738-
$or: [
739-
{ storedAtTimestamp: { $exists: false } },
740-
{
741-
$expr: { $lt: ["$storedAtTimestamp", "$lastUpdatedTimestamp"] },
742-
},
743-
],
744-
})
745-
.sort({ _id: 1 }) // Consistent ordering is important for pagination
746-
.skip(skip)
747-
.limit(limit)
748-
.lean<UserCommitmentRecord[]>();
736+
const docs = await this.tables?.commitment.aggregate<UserCommitmentRecord>([
737+
{
738+
$match: {
739+
$or: [
740+
{ storedAtTimestamp: { $exists: false } },
741+
{
742+
$expr: {
743+
$lt: [
744+
{
745+
$convert: {
746+
input: "$storedAtTimestamp",
747+
to: "date",
748+
},
749+
},
750+
{
751+
$convert: {
752+
input: "$lastUpdatedTimestamp",
753+
to: "date",
754+
},
755+
},
756+
],
757+
},
758+
},
759+
],
760+
},
761+
},
762+
{
763+
$sort: { _id: 1 },
764+
},
765+
{
766+
$skip: skip,
767+
},
768+
{
769+
$limit: limit,
770+
},
771+
]);
749772
return docs || [];
750773
}
751774

@@ -790,20 +813,42 @@ export class ProviderDatabase
790813
limit = 1000,
791814
skip = 0,
792815
): Promise<PoWCaptchaRecord[]> {
793-
const docs = await this.tables?.powcaptcha
794-
.find<PoWCaptchaRecord[]>({
795-
$or: [
796-
{ storedAtTimestamp: { $exists: false } },
797-
{
798-
$expr: { $lt: ["$storedAtTimestamp", "$lastUpdatedTimestamp"] },
799-
},
800-
],
801-
})
802-
.sort({ _id: 1 }) // Consistent ordering is important for pagination
803-
.skip(skip)
804-
.limit(limit)
805-
.lean<PoWCaptchaRecord[]>();
806-
816+
const docs = await this.tables?.powcaptcha.aggregate<PoWCaptchaRecord>([
817+
{
818+
$match: {
819+
$or: [
820+
{ storedAtTimestamp: { $exists: false } },
821+
{
822+
$expr: {
823+
$lt: [
824+
{
825+
$convert: {
826+
input: "$storedAtTimestamp",
827+
to: "date",
828+
},
829+
},
830+
{
831+
$convert: {
832+
input: "$lastUpdatedTimestamp",
833+
to: "date",
834+
},
835+
},
836+
],
837+
},
838+
},
839+
],
840+
},
841+
},
842+
{
843+
$sort: { _id: 1 },
844+
},
845+
{
846+
$skip: skip,
847+
},
848+
{
849+
$limit: limit,
850+
},
851+
]);
807852
return docs || [];
808853
}
809854

packages/provider/src/tasks/client/clientTasks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class ClientTaskManager {
7979

8080
// Process image commitments with cursor
8181
let processedCommitments = 0;
82+
8283
await this.processBatchesWithCursor(
8384
async (skip: number) =>
8485
await this.providerDB.getUnstoredDappUserCommitments(

0 commit comments

Comments
 (0)