Skip to content

Commit

Permalink
✨ Add some lastUpdateBlock to have some rpc level request caching
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Nov 28, 2024
1 parent 4d19b6a commit 9ea3030
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/ponder/ponder.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const productTable = onchainTable(
createTimestamp: t.bigint().notNull(),
lastUpdateTimestamp: t.bigint(),

lastUpdateBlock: t.bigint().notNull(),

metadataUrl: t.varchar(),
}),
(table) => ({
Expand Down Expand Up @@ -114,6 +116,8 @@ export const campaignTable = onchainTable(
interactionContractId: t.hex().notNull(),
attached: t.boolean().notNull(),

lastUpdateBlock: t.bigint().notNull(),

attachTimestamp: t.bigint().notNull(),
detachTimestamp: t.bigint(),

Expand Down
1 change: 1 addition & 0 deletions packages/ponder/src/api/campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ponder.get("/campaign", async (ctx) => {
productId: campaignTable.productId,
attached: campaignTable.attached,
banking: campaignTable.bankingContractId,
lastUpdateBlock: campaignTable.lastUpdateBlock,
token: bankingContractTable.tokenId,
})
.from(campaignTable)
Expand Down
1 change: 1 addition & 0 deletions packages/ponder/src/campaign/campaignBank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ ponder.on(
})
.set({
isAuthorisedOnBanking: event.args.isAllowed,
lastUpdateBlock: event.block.number,
});
}
);
Expand Down
1 change: 1 addition & 0 deletions packages/ponder/src/campaign/campaignCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ ponder.on(
? configResult.result[2]
: undefined,
isAuthorisedOnBanking: false,
lastUpdateBlock: event.block.number,
});

// Upsert press campaign stats if it's the right type
Expand Down
2 changes: 2 additions & 0 deletions packages/ponder/src/campaign/campaignInteractionLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ ponder.on(
version,
attached: true,
attachTimestamp: event.block.timestamp,
lastUpdateBlock: event.block.number,
});

// Upsert press campaign stats if it's the right type
Expand All @@ -76,6 +77,7 @@ ponder.on(
.set({
attached: false,
detachTimestamp: event.block.timestamp,
lastUpdateBlock: event.block.number,
});
}
);
2 changes: 2 additions & 0 deletions packages/ponder/src/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ponder.on("ProductRegistry:ProductMinted", async ({ event, context }) => {
name: bytesToString(event.args.name),
createTimestamp: event.block.timestamp,
metadataUrl,
lastUpdateBlock: event.block.number,
});
});

Expand All @@ -40,5 +41,6 @@ ponder.on("ProductRegistry:ProductUpdated", async ({ event, context }) => {
productTypes: event.args.productTypes,
lastUpdateTimestamp: event.block.timestamp,
metadataUrl: metadataUrl ?? current.metadataUrl,
lastUpdateBlock: event.block.number,
}));
});

0 comments on commit 9ea3030

Please sign in to comment.