From 13c541165dd9905985376fea3964846db415dfb4 Mon Sep 17 00:00:00 2001 From: Bruno Leal Date: Wed, 13 Nov 2024 22:23:25 -0300 Subject: [PATCH] refactor getProposals API by removing unnecessary comments --- .../routes/v2-state/get_proposals/get_proposals.ts | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/api/routes/v2-state/get_proposals/get_proposals.ts b/src/api/routes/v2-state/get_proposals/get_proposals.ts index 060743b5..2e1187be 100644 --- a/src/api/routes/v2-state/get_proposals/get_proposals.ts +++ b/src/api/routes/v2-state/get_proposals/get_proposals.ts @@ -5,7 +5,6 @@ import { estypes } from '@elastic/elasticsearch'; async function getProposals(fastify: FastifyInstance, request: FastifyRequest) { const query: any = request.query; - // Pagination let skip: number; let limit: number; skip = parseInt(query.skip, 10); @@ -29,9 +28,8 @@ async function getProposals(fastify: FastifyInstance, request: FastifyRequest) { }; let stateResult: any[]; - const startTime = Date.now(); // Inicia o cronômetro para a consulta + const startTime = Date.now(); - // Verifica se a consulta deve ser feita no MongoDB if (fastify.manager.config.indexer.experimental_mongodb_state && fastify.manager.conn.mongodb && query.useMongo === 'true') { const dbName = `${fastify.manager.conn.mongodb.database_prefix}_${fastify.manager.chain}`; const collection = fastify.mongo.client.db(dbName).collection('proposals'); @@ -60,8 +58,6 @@ async function getProposals(fastify: FastifyInstance, request: FastifyRequest) { mongoQuery["provided_approvals.actor"] = query.provided; } - // Consultar MongoDB - console.log(`Consultar Mongo`) const lastBlockResult = await fastify.mongo.client.db(dbName).collection('proposals').find().sort({ block_num: -1 }).limit(1).toArray(); response.last_indexed_block = lastBlockResult[0]?.block_num || 0; response.last_indexed_block_time = lastBlockResult[0]?.block_time || ''; @@ -74,8 +70,6 @@ async function getProposals(fastify: FastifyInstance, request: FastifyRequest) { .toArray(); } else { - // Caso não seja no MongoDB, faz a consulta no Elasticsearch - console.log(`Consultar Elastic`) let queryStruct: any = { bool: { must: [] } }; if (query.account) { const accounts = query.account.split(','); @@ -110,7 +104,6 @@ async function getProposals(fastify: FastifyInstance, request: FastifyRequest) { queryStruct = { match_all: {} }; } - // Consultar Elasticsearch const esResult = await fastify.elastic.search({ index: `${fastify.manager.chain}-table-proposals-*`, from: skip || 0, @@ -123,19 +116,15 @@ async function getProposals(fastify: FastifyInstance, request: FastifyRequest) { stateResult = esResult.hits.hits.map((hit: any) => hit._source); response.total = (esResult.hits.total as estypes.SearchTotalHits).value; - // Pegando o último bloco indexado response.last_indexed_block = esResult.hits.hits.length > 0 ? esResult.hits.hits[0]._source.block_num : 0; response.last_indexed_block_time = esResult.hits.hits.length > 0 ? esResult.hits.hits[0]._source.block_time : ''; } - // Formatar resposta com os dados obtidos for (const proposal of stateResult) { response.proposals.push(proposal); } - // Calculando o tempo de consulta response.query_time_ms = Date.now() - startTime; - return response; }