From 58cdf3760f012807115cc03edf02498fa8aa32b1 Mon Sep 17 00:00:00 2001 From: RetricSu Date: Tue, 12 Jul 2022 11:37:54 +0800 Subject: [PATCH] chore: tune latest median tx to 50 --- packages/api-server/src/db/constant.ts | 2 ++ packages/api-server/src/db/query.ts | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/api-server/src/db/constant.ts b/packages/api-server/src/db/constant.ts index 19f0dab2..b16b083a 100644 --- a/packages/api-server/src/db/constant.ts +++ b/packages/api-server/src/db/constant.ts @@ -2,3 +2,5 @@ export const MAX_QUERY_NUMBER = 10000; export const MAX_QUERY_TIME_MILSECS = 1000 * 10; // 10 seconds export const MAX_QUERY_ROUNDS = 100; + +export const LATEST_MEDIAN_GAS_PRICE = 50; diff --git a/packages/api-server/src/db/query.ts b/packages/api-server/src/db/query.ts index b64c115f..c1bd9f05 100644 --- a/packages/api-server/src/db/query.ts +++ b/packages/api-server/src/db/query.ts @@ -10,7 +10,7 @@ import { import Knex, { Knex as KnexType } from "knex"; import { LogQueryOption } from "./types"; import { envConfig } from "../base/env-config"; -import { MAX_QUERY_NUMBER } from "./constant"; +import { LATEST_MEDIAN_GAS_PRICE, MAX_QUERY_NUMBER } from "./constant"; import { QUERY_OFFSET_REACHED_END } from "../methods/constant"; import { formatDecimal, @@ -402,10 +402,10 @@ export class Query { throw new Error("invalid params!"); } - // Latest 500 transactions median gas_price + // Latest ${LATEST_MEDIAN_GAS_PRICE} transactions median gas_price async getMedianGasPrice(): Promise { const sql = `SELECT (PERCENTILE_CONT(0.5) WITHIN GROUP(ORDER BY gas_price)) AS median FROM (SELECT gas_price FROM transactions ORDER BY id DESC LIMIT ?) AS gas_price;`; - const result = await this.knex.raw(sql, [500]); + const result = await this.knex.raw(sql, [LATEST_MEDIAN_GAS_PRICE]); const median = result.rows[0]?.median; if (median == null) {