@@ -12,6 +12,7 @@ import { BlockPointer, ChainIndexingStatus, IndexingStatus } from './types'
12
12
import pRetry , { Options } from 'p-retry'
13
13
import axios , { AxiosInstance } from 'axios'
14
14
import fetch from 'isomorphic-fetch'
15
+ import { Action } from './indexer-management'
15
16
16
17
interface indexNode {
17
18
id : string
@@ -103,9 +104,15 @@ export class GraphNode {
103
104
await pRetry (
104
105
async ( ) => {
105
106
const deployments = await this . subgraphDeployments ( )
106
- this . logger . info ( `Successfully connected to indexing status API` , {
107
- currentDeployments : deployments . map ( ( deployment ) => deployment . display ) ,
108
- } )
107
+ if ( deployments . length < 100 ) {
108
+ this . logger . info ( `Successfully connected to indexing status API` , {
109
+ currentDeployments : deployments . map ( ( deployment ) => deployment . display ) ,
110
+ } )
111
+ } else {
112
+ this . logger . info ( `Successfully connected to indexing status API` , {
113
+ currentDeploymentCount : deployments . length ,
114
+ } )
115
+ }
109
116
} ,
110
117
{
111
118
retries : 10 ,
@@ -148,10 +155,98 @@ export class GraphNode {
148
155
)
149
156
}
150
157
158
+ public async subgraphDeploymentAssignmentsForAllocateActions (
159
+ subgraphStatus : SubgraphStatus ,
160
+ actions : Action [ ] ,
161
+ ) : Promise < SubgraphDeploymentAssignment [ ] > {
162
+ const deploymentIDs = actions . map ( ( action ) => action . deploymentID )
163
+
164
+ const nodeOnlyResult = await this . status
165
+ . query (
166
+ gql `
167
+ query indexingStatuses($subgraphs: [String!]!) {
168
+ indexingStatuses(subgraphs: $subgraphs) {
169
+ subgraphDeployment: subgraph
170
+ node
171
+ }
172
+ }
173
+ ` ,
174
+ { subgraphs : deploymentIDs } ,
175
+ )
176
+ . toPromise ( )
177
+
178
+ if ( nodeOnlyResult . error ) {
179
+ throw nodeOnlyResult . error
180
+ }
181
+
182
+ const withAssignments : string [ ] = nodeOnlyResult . data . indexingStatuses
183
+ . filter (
184
+ ( result : { node : string | null } ) =>
185
+ result . node !== null && result . node !== undefined ,
186
+ )
187
+ . map ( ( result : { subgraphDeployment : string } ) => result . subgraphDeployment )
188
+
189
+ const result = await this . status
190
+ . query (
191
+ gql `
192
+ query indexingStatuses($subgraphs: [String!]!) {
193
+ indexingStatuses(subgraphs: $subgraphs) {
194
+ subgraphDeployment: subgraph
195
+ node
196
+ paused
197
+ }
198
+ }
199
+ ` ,
200
+ { subgraphs : withAssignments } ,
201
+ )
202
+ . toPromise ( )
203
+
204
+ if ( result . error ) {
205
+ throw result . error
206
+ }
207
+
208
+ if ( ! result . data . indexingStatuses || result . data . length === 0 ) {
209
+ this . logger . warn ( `No 'indexingStatuses' data returned from index nodes` , {
210
+ data : result . data ,
211
+ } )
212
+ return [ ]
213
+ }
214
+
215
+ type QueryResult = {
216
+ subgraphDeployment : string
217
+ node : string | undefined
218
+ paused : boolean | undefined
219
+ }
220
+
221
+ const results = result . data . indexingStatuses
222
+ . filter ( ( status : QueryResult ) => {
223
+ if ( subgraphStatus === SubgraphStatus . ACTIVE ) {
224
+ return (
225
+ status . paused === false ||
226
+ ( status . paused === undefined && status . node !== 'removed' )
227
+ )
228
+ } else if ( subgraphStatus === SubgraphStatus . PAUSED ) {
229
+ return status . node === 'removed' || status . paused === true
230
+ } else if ( subgraphStatus === SubgraphStatus . ALL ) {
231
+ return true
232
+ }
233
+ } )
234
+ . map ( ( status : QueryResult ) => {
235
+ return {
236
+ id : new SubgraphDeploymentID ( status . subgraphDeployment ) ,
237
+ node : status . node ,
238
+ paused : status . paused ?? status . node === 'removed' ,
239
+ }
240
+ } )
241
+
242
+ return results
243
+ }
244
+
151
245
public async subgraphDeploymentsAssignments (
152
246
subgraphStatus : SubgraphStatus ,
153
247
) : Promise < SubgraphDeploymentAssignment [ ] > {
154
248
try {
249
+ const startTimeMs = Date . now ( )
155
250
this . logger . debug ( 'Fetch subgraph deployment assignments' )
156
251
157
252
// FIXME: remove this initial check for just node when graph-node releases
@@ -170,6 +265,10 @@ export class GraphNode {
170
265
)
171
266
. toPromise ( )
172
267
268
+ this . logger . debug (
269
+ `Fetch subgraph deployment assignments took ${ Date . now ( ) - startTimeMs } ms` ,
270
+ )
271
+
173
272
if ( nodeOnlyResult . error ) {
174
273
throw nodeOnlyResult . error
175
274
}
@@ -214,7 +313,7 @@ export class GraphNode {
214
313
paused : boolean | undefined
215
314
}
216
315
217
- return result . data . indexingStatuses
316
+ const results = result . data . indexingStatuses
218
317
. filter ( ( status : QueryResult ) => {
219
318
if ( subgraphStatus === SubgraphStatus . ACTIVE ) {
220
319
return (
@@ -234,6 +333,12 @@ export class GraphNode {
234
333
paused : status . paused ?? status . node === 'removed' ,
235
334
}
236
335
} )
336
+ this . logger . debug (
337
+ `Fetching mapped subgraph deployment ${ results . length } assignments took ${
338
+ Date . now ( ) - startTimeMs
339
+ } ms`,
340
+ )
341
+ return results
237
342
} catch ( error ) {
238
343
const err = indexerError ( IndexerErrorCode . IE018 , error )
239
344
this . logger . error ( `Failed to query indexing status API` , { err } )
0 commit comments