Skip to content

Commit

Permalink
Update query to get unstored commitments (#1590)
Browse files Browse the repository at this point in the history
  • Loading branch information
forgetso authored Dec 22, 2024
2 parents 6bff959 + aec79f0 commit c213cbf
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 27 deletions.
99 changes: 72 additions & 27 deletions packages/database/src/databases/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,19 +733,42 @@ export class ProviderDatabase
limit = 1000,
skip = 0,
): Promise<UserCommitmentRecord[]> {
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<UserCommitmentRecord[]>();
const docs = await this.tables?.commitment.aggregate<UserCommitmentRecord>([
{
$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 || [];
}

Expand Down Expand Up @@ -790,20 +813,42 @@ export class ProviderDatabase
limit = 1000,
skip = 0,
): Promise<PoWCaptchaRecord[]> {
const docs = await this.tables?.powcaptcha
.find<PoWCaptchaRecord[]>({
$or: [
{ storedAtTimestamp: { $exists: false } },
{
$expr: { $lt: ["$storedAtTimestamp", "$lastUpdatedTimestamp"] },
},
],
})
.sort({ _id: 1 }) // Consistent ordering is important for pagination
.skip(skip)
.limit(limit)
.lean<PoWCaptchaRecord[]>();

const docs = await this.tables?.powcaptcha.aggregate<PoWCaptchaRecord>([
{
$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 || [];
}

Expand Down
1 change: 1 addition & 0 deletions packages/provider/src/tasks/client/clientTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c213cbf

Please sign in to comment.