Skip to content

Commit

Permalink
Fetch only recent ops
Browse files Browse the repository at this point in the history
  • Loading branch information
Destiner committed May 17, 2024
1 parent c7c3544 commit 0475003
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/pages/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ const ops = ref<FeedUserOp[]>([]);
async function fetch(): Promise<void> {
const LIMIT = 20;
const indexerService = new IndexerService(indexerEndpoint);
const startBlock = ops.value[0]?.blockTimestamp;
const startTimestamp =
ops.value[0]?.blockTimestamp || Math.floor(Date.now() / 1000) - 60 * 60;
const newOps = await indexerService.getLatestUserOps(
LIMIT,
startTimestamp,
chain.value || undefined,
startBlock,
);
const opList = [...newOps, ...ops.value];
opList.sort((a, b) => b.blockTimestamp - a.blockTimestamp);
Expand Down
4 changes: 2 additions & 2 deletions src/services/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,15 @@ class Service {

public async getLatestUserOps(
limit: number,
startTimestamp: number,
chain?: Chain,
startBlock?: number,
): Promise<FeedUserOp[]> {
const query = `{
UserOp(
limit: ${limit},
where: {
${chain ? `chainId: { _eq: ${chain} },` : ''}
${startBlock ? `blockTimestamp: { _gt: ${startBlock} },` : ''}
${startTimestamp ? `blockTimestamp: { _gt: ${startTimestamp} },` : ''}
},
order_by: {
blockTimestamp: desc
Expand Down

0 comments on commit 0475003

Please sign in to comment.