Skip to content

Commit 20af261

Browse files
committed
common: fix subgraph pagination
1 parent 0f99796 commit 20af261

File tree

1 file changed

+10
-17
lines changed
  • packages/indexer-common/src/indexer-management

1 file changed

+10
-17
lines changed

packages/indexer-common/src/indexer-management/monitor.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -407,29 +407,27 @@ export class NetworkMonitor {
407407
}
408408
let subgraphs: Subgraph[] = []
409409
const queryProgress = {
410-
lastId: '',
411-
first: 20,
410+
pageSize: 1000,
412411
fetched: 0,
413412
exhausted: false,
414413
retriesRemaining: 10,
415414
}
416-
this.logger.info(`Query subgraphs in batches of ${queryProgress.first}`)
415+
this.logger.info(`Query subgraphs in batches of ${queryProgress.pageSize}`)
416+
const groups: string[][] = []
417+
for (let i = 0; i < ids.length; i += queryProgress.pageSize) {
418+
groups.push(ids.slice(i, i + queryProgress.pageSize))
419+
}
417420

418-
while (!queryProgress.exhausted) {
421+
for (const group of groups) {
419422
this.logger.debug(`Query subgraphs by id`, {
420423
queryProgress: queryProgress,
421424
subgraphIds: ids,
422425
})
423426
try {
424427
const result = await this.networkSubgraph.checkedQuery(
425428
gql`
426-
query subgraphs($first: Int!, $lastId: String!, $subgraphs: [String!]!) {
427-
subgraphs(
428-
where: { id_gt: $lastId, id_in: $subgraphs }
429-
orderBy: id
430-
orderDirection: asc
431-
first: $first
432-
) {
429+
query subgraphs($subgraphs: [String!]!) {
430+
subgraphs(where: { id_in: $subgraphs }, orderBy: id, orderDirection: asc) {
433431
id
434432
createdAt
435433
versionCount
@@ -444,9 +442,7 @@ export class NetworkMonitor {
444442
}
445443
`,
446444
{
447-
first: queryProgress.first,
448-
lastId: queryProgress.lastId,
449-
subgraphs: ids,
445+
subgraphs: group,
450446
},
451447
)
452448

@@ -479,10 +475,7 @@ export class NetworkMonitor {
479475
throw new Error(`No subgraph deployments found matching provided ids: ${ids}`)
480476
}
481477

482-
queryProgress.exhausted = results.length < queryProgress.first
483478
queryProgress.fetched += results.length
484-
queryProgress.lastId = results[results.length - 1].id
485-
486479
subgraphs = subgraphs.concat(results)
487480
} catch (error) {
488481
queryProgress.retriesRemaining--

0 commit comments

Comments
 (0)