From 349e1ca75bcb728f17231326e850dea1d4ee54d1 Mon Sep 17 00:00:00 2001 From: tilacog Date: Wed, 19 Oct 2022 18:20:11 -0300 Subject: [PATCH 1/4] cli: add a `--first` option to limit action query results --- packages/indexer-cli/src/actions.ts | 11 +++++-- .../src/commands/indexer/actions/get.ts | 33 ++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/packages/indexer-cli/src/actions.ts b/packages/indexer-cli/src/actions.ts index 55a5acea2..e654f9a77 100644 --- a/packages/indexer-cli/src/actions.ts +++ b/packages/indexer-cli/src/actions.ts @@ -276,6 +276,7 @@ export async function fetchAction( export async function fetchActions( client: IndexerManagementClient, actionFilter: ActionFilter, + first?: number, orderBy?: ActionParams, orderDirection?: OrderDirection, ): Promise { @@ -284,10 +285,16 @@ export async function fetchActions( gql` query actions( $filter: ActionFilter! + $first: Int $orderBy: ActionParams $orderDirection: OrderDirection ) { - actions(filter: $filter, orderBy: $orderBy, orderDirection: $orderDirection) { + actions( + filter: $filter + orderBy: $orderBy + orderDirection: $orderDirection + first: $first + ) { id type allocationID @@ -304,7 +311,7 @@ export async function fetchActions( } } `, - { filter: actionFilter, orderBy, orderDirection }, + { filter: actionFilter, orderBy, orderDirection, first }, ) .toPromise() diff --git a/packages/indexer-cli/src/commands/indexer/actions/get.ts b/packages/indexer-cli/src/commands/indexer/actions/get.ts index 87f0d3764..f96d8b96b 100644 --- a/packages/indexer-cli/src/commands/indexer/actions/get.ts +++ b/packages/indexer-cli/src/commands/indexer/actions/get.ts @@ -21,11 +21,12 @@ ${chalk.dim('Options:')} -h, --help Show usage information --type allocate|unallocate|reallocate|collect Filter by type - --status queued|approved|pending|success|failed|canceled Filter by status + --status queued|approved|pending|success|failed|canceled Filter by status --source Fetch only actions queued by a specific source --reason Fetch only actions queued for a specific reason --orderBy id|deploymentID|amount|priority|...|updatedAt Order actions by a specific field (default: id) --orderDirection asc|desc Order direction (default: desc) + --first [N] Fetch only the N first records (default: all records) -o, --output table|json|yaml Choose the output format: table (default), JSON, or YAML ` @@ -38,8 +39,19 @@ module.exports = { const inputSpinner = toolbox.print.spin('Processing inputs') - const { type, status, source, reason, orderBy, orderDirection, h, help, o, output } = - parameters.options + const { + type, + status, + source, + reason, + orderBy, + orderDirection, + h, + help, + o, + output, + first, + } = parameters.options const [action] = fixParameters(parameters, { h, help }) || [] let orderByParam = ActionParams.ID @@ -50,7 +62,6 @@ module.exports = { inputSpinner.stopAndPersist({ symbol: '💁', text: HELP }) return } - try { if (!['json', 'yaml', 'table'].includes(outputFormat)) { throw Error( @@ -91,6 +102,11 @@ module.exports = { ? OrderDirection[orderDirection.toUpperCase() as keyof typeof OrderDirection] : OrderDirection.DESC } + + if (!['undefined', 'number'].includes(typeof first)) { + throw Error(`Invalid value for '--first' option, must have a numeric value.`) + } + inputSpinner.succeed('Processed input parameters') } catch (error) { inputSpinner.fail(error.toString()) @@ -110,7 +126,13 @@ module.exports = { let actions: ActionResult[] = [] if (action) { if (action === 'all') { - actions = await fetchActions(client, {}, orderByParam, orderDirectionValue) + actions = await fetchActions( + client, + {}, + first, + orderByParam, + orderDirectionValue, + ) } else { actions = [await fetchAction(client, +action)] } @@ -123,6 +145,7 @@ module.exports = { source, reason, }, + first, orderByParam, orderDirectionValue, ) From a7f5993449913eefecf42e5d84e53b3a5a780897 Mon Sep 17 00:00:00 2001 From: tilacog Date: Wed, 19 Oct 2022 18:20:38 -0300 Subject: [PATCH 2/4] common: introduces limits to action resolver results --- .../indexer-common/src/indexer-management/actions.ts | 2 ++ .../indexer-common/src/indexer-management/client.ts | 1 + .../src/indexer-management/resolvers/actions.ts | 11 +++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/indexer-common/src/indexer-management/actions.ts b/packages/indexer-common/src/indexer-management/actions.ts index 462c5ca81..29cedebb8 100644 --- a/packages/indexer-common/src/indexer-management/actions.ts +++ b/packages/indexer-common/src/indexer-management/actions.ts @@ -157,6 +157,7 @@ export class ActionManager { filter: ActionFilter, orderBy?: ActionParams, orderDirection?: OrderDirection, + first?: number, ): Promise { const filterObject = JSON.parse(JSON.stringify(filter)) const orderObject: Order = orderBy @@ -165,6 +166,7 @@ export class ActionManager { return await this.models.Action.findAll({ where: filterObject, order: orderObject, + limit: first, }) } } diff --git a/packages/indexer-common/src/indexer-management/client.ts b/packages/indexer-common/src/indexer-management/client.ts index 73003cdad..a81bf39fc 100644 --- a/packages/indexer-common/src/indexer-management/client.ts +++ b/packages/indexer-common/src/indexer-management/client.ts @@ -376,6 +376,7 @@ const SCHEMA_SDL = gql` filter: ActionFilter orderBy: ActionParams orderDirection: OrderDirection + first: Int ): [Action]! } diff --git a/packages/indexer-common/src/indexer-management/resolvers/actions.ts b/packages/indexer-common/src/indexer-management/resolvers/actions.ts index 195f472bb..c544263f6 100644 --- a/packages/indexer-common/src/indexer-management/resolvers/actions.ts +++ b/packages/indexer-common/src/indexer-management/resolvers/actions.ts @@ -118,15 +118,22 @@ export default { filter, orderBy, orderDirection, - }: { filter: ActionFilter; orderBy: ActionParams; orderDirection: OrderDirection }, + first, + }: { + filter: ActionFilter + orderBy: ActionParams + orderDirection: OrderDirection + first: number + }, { actionManager, logger }: IndexerManagementResolverContext, ): Promise => { logger.debug(`Execute 'actions' query`, { filter, orderBy, orderDirection, + first, }) - return await actionManager.fetchActions(filter, orderBy, orderDirection) + return await actionManager.fetchActions(filter, orderBy, orderDirection, first) }, queueActions: async ( From f5ccea74b43b11dda0674b79686e9ff69c725350 Mon Sep 17 00:00:00 2001 From: Adam Fuller Date: Thu, 20 Oct 2022 19:57:08 +0100 Subject: [PATCH 3/4] Update indexer components to 0.20.4 on testnet --- docs/networks.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/networks.md b/docs/networks.md index 019bf86b7..fc80a463a 100644 --- a/docs/networks.md +++ b/docs/networks.md @@ -17,9 +17,9 @@ For testnet: | Component | Release | | --------------- | -------------------------------------------------------------------------- | | contracts | [1.13.0](https://github.com/graphprotocol/contracts/releases/tag/v1.13.0) | -| indexer-agent | [0.20.3](https://github.com/graphprotocol/indexer/releases/tag/v0.20.3) | -| indexer-cli | [0.20.3](https://github.com/graphprotocol/indexer/releases/tag/v0.20.3) | -| indexer-service | [0.20.3](https://github.com/graphprotocol/indexer/releases/tag/v0.20.3) | +| indexer-agent | [0.20.4](https://github.com/graphprotocol/indexer/releases/tag/v0.20.4) | +| indexer-cli | [0.20.4](https://github.com/graphprotocol/indexer/releases/tag/v0.20.4) | +| indexer-service | [0.20.4](https://github.com/graphprotocol/indexer/releases/tag/v0.20.4) | | graph-node | [0.28.2](https://github.com/graphprotocol/graph-node/releases/tag/v0.28.2) | ## Mainnet (https://network.thegraph.com) From c7d670cbf56a6806afca4cc21e9810d48afcffe7 Mon Sep 17 00:00:00 2001 From: tilacog Date: Mon, 24 Oct 2022 13:36:54 -0300 Subject: [PATCH 4/4] agent: update @graphprotocol/contracts to v1.16.0 --- packages/indexer-agent/package.json | 2 +- yarn.lock | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/indexer-agent/package.json b/packages/indexer-agent/package.json index dd200a022..fb84247a1 100644 --- a/packages/indexer-agent/package.json +++ b/packages/indexer-agent/package.json @@ -30,7 +30,7 @@ }, "dependencies": { "@graphprotocol/common-ts": "1.8.6", - "@graphprotocol/contracts": "1.13.0", + "@graphprotocol/contracts": "1.16.0", "@graphprotocol/indexer-common": "^0.20.4", "@thi.ng/heaps": "^1.3.1", "@uniswap/sdk": "3.0.3", diff --git a/yarn.lock b/yarn.lock index c796d06df..596d34976 100644 --- a/yarn.lock +++ b/yarn.lock @@ -811,6 +811,13 @@ dependencies: ethers "^5.4.4" +"@graphprotocol/contracts@1.16.0": + version "1.16.0" + resolved "https://registry.yarnpkg.com/@graphprotocol/contracts/-/contracts-1.16.0.tgz#3ecc43277b4da8ccbd14fb6ea42c93c888e52d53" + integrity sha512-/UldTtx6/GbeNqWlMf2P3a4l6gQYEiNdG+FooUfDQYansnOmLCe+vmnRnh+w2cnf3L6KteX2Qxih4ajI7q1gcQ== + dependencies: + ethers "^5.4.4" + "@graphprotocol/cost-model@0.1.14": version "0.1.14" resolved "https://registry.npmjs.org/@graphprotocol/cost-model/-/cost-model-0.1.14.tgz#0eeab1c3c63d94600c2cc67e46965e0ba65b2353"