From 04750036cf4bb26103a7feb4ade63a60fc354d7c Mon Sep 17 00:00:00 2001 From: Timur Badretdinov Date: Fri, 17 May 2024 12:11:49 +0100 Subject: [PATCH] Fetch only recent ops --- src/pages/Home.vue | 5 +++-- src/services/indexer.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pages/Home.vue b/src/pages/Home.vue index 3f04d75..badb7c2 100644 --- a/src/pages/Home.vue +++ b/src/pages/Home.vue @@ -56,11 +56,12 @@ const ops = ref([]); async function fetch(): Promise { 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); diff --git a/src/services/indexer.ts b/src/services/indexer.ts index a1d4a3f..3c6b0df 100644 --- a/src/services/indexer.ts +++ b/src/services/indexer.ts @@ -269,15 +269,15 @@ class Service { public async getLatestUserOps( limit: number, + startTimestamp: number, chain?: Chain, - startBlock?: number, ): Promise { const query = `{ UserOp( limit: ${limit}, where: { ${chain ? `chainId: { _eq: ${chain} },` : ''} - ${startBlock ? `blockTimestamp: { _gt: ${startBlock} },` : ''} + ${startTimestamp ? `blockTimestamp: { _gt: ${startTimestamp} },` : ''} }, order_by: { blockTimestamp: desc