Skip to content

Commit

Permalink
common: fix subgraph pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
dwerner committed Dec 12, 2024
1 parent 0f99796 commit 20af261
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions packages/indexer-common/src/indexer-management/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,29 +407,27 @@ export class NetworkMonitor {
}
let subgraphs: Subgraph[] = []
const queryProgress = {
lastId: '',
first: 20,
pageSize: 1000,
fetched: 0,
exhausted: false,
retriesRemaining: 10,
}
this.logger.info(`Query subgraphs in batches of ${queryProgress.first}`)
this.logger.info(`Query subgraphs in batches of ${queryProgress.pageSize}`)
const groups: string[][] = []
for (let i = 0; i < ids.length; i += queryProgress.pageSize) {
groups.push(ids.slice(i, i + queryProgress.pageSize))
}

while (!queryProgress.exhausted) {
for (const group of groups) {
this.logger.debug(`Query subgraphs by id`, {
queryProgress: queryProgress,
subgraphIds: ids,
})
try {
const result = await this.networkSubgraph.checkedQuery(
gql`
query subgraphs($first: Int!, $lastId: String!, $subgraphs: [String!]!) {
subgraphs(
where: { id_gt: $lastId, id_in: $subgraphs }
orderBy: id
orderDirection: asc
first: $first
) {
query subgraphs($subgraphs: [String!]!) {
subgraphs(where: { id_in: $subgraphs }, orderBy: id, orderDirection: asc) {
id
createdAt
versionCount
Expand All @@ -444,9 +442,7 @@ export class NetworkMonitor {
}
`,
{
first: queryProgress.first,
lastId: queryProgress.lastId,
subgraphs: ids,
subgraphs: group,
},
)

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

queryProgress.exhausted = results.length < queryProgress.first
queryProgress.fetched += results.length
queryProgress.lastId = results[results.length - 1].id

subgraphs = subgraphs.concat(results)
} catch (error) {
queryProgress.retriesRemaining--
Expand Down

0 comments on commit 20af261

Please sign in to comment.