From 19f0d4d16b2a498acf93f22ea47643752eac096d Mon Sep 17 00:00:00 2001 From: pablomendezroyo Date: Mon, 30 Sep 2024 11:42:52 +0200 Subject: [PATCH] return map indexed by validator index number instead of string --- .../brain/src/modules/apiClients/postgres/index.ts | 12 ++++++++---- .../brain/src/modules/validatorsDataIngest/index.ts | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/brain/src/modules/apiClients/postgres/index.ts b/packages/brain/src/modules/apiClients/postgres/index.ts index 30f03b7e..0fe2c89e 100644 --- a/packages/brain/src/modules/apiClients/postgres/index.ts +++ b/packages/brain/src/modules/apiClients/postgres/index.ts @@ -243,7 +243,7 @@ WHERE ${Columns.validatorIndex} = ANY($1) validatorIndexes: string[]; startEpoch: number; endEpoch: number; - }): Promise> { + }): Promise> { const query = ` SELECT * FROM ${this.tableName} WHERE ${Columns.validatorIndex} = ANY($1) @@ -251,9 +251,13 @@ AND ${Columns.epoch} >= $2 AND ${Columns.epoch} <= $3 `; - const result = await this.sql.unsafe(query, [validatorIndexes, startEpoch, endEpoch]); + const result = (await this.sql.unsafe(query, [ + validatorIndexes, + startEpoch, + endEpoch + ])) as ValidatorPerformancePostgres[]; - return result.reduce((map: Map, row) => { + return result.reduce((map: Map, row) => { const key = row.validator_index; // print type ofs @@ -279,7 +283,7 @@ AND ${Columns.epoch} <= $3 else map.set(key, [performanceData]); return map; - }, new Map()); + }, new Map()); } /** diff --git a/packages/brain/src/modules/validatorsDataIngest/index.ts b/packages/brain/src/modules/validatorsDataIngest/index.ts index 488a504f..d4d9c5f6 100644 --- a/packages/brain/src/modules/validatorsDataIngest/index.ts +++ b/packages/brain/src/modules/validatorsDataIngest/index.ts @@ -46,12 +46,12 @@ export async function fetchAndProcessValidatorsData({ granularity?: Granularity; }): Promise< Map< - string, // validatorIndex + number, // validatorIndex ValidatorsDataProcessed // processed data of the validator > > { logger.info("Processing validators data"); - const mapValidatorPerformance = new Map(); + const mapValidatorPerformance = new Map(); // Get start timestamp and end timestamp const endDate = new Date();