From 6548aa418ca98583c38ab46d2c187090fc0e438f 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 | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/api-server/src/db/constant.ts b/packages/api-server/src/db/constant.ts index 26b295c3..07b4b580 100644 --- a/packages/api-server/src/db/constant.ts +++ b/packages/api-server/src/db/constant.ts @@ -1,3 +1,5 @@ export const DEFAULT_MAX_QUERY_NUMBER = 10000; export const DEFAULT_MAX_QUERY_TIME_MILSECS = 1000 * 10; // 10 seconds export const DEFAULT_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 16740118..52334734 100644 --- a/packages/api-server/src/db/query.ts +++ b/packages/api-server/src/db/query.ts @@ -10,6 +10,7 @@ import { import Knex, { Knex as KnexType } from "knex"; import { LogQueryOption } from "./types"; import { envConfig } from "../base/env-config"; +import { LATEST_MEDIAN_GAS_PRICE } from "./constant"; import { QUERY_OFFSET_REACHED_END } from "../methods/constant"; import { formatDecimal, @@ -426,10 +427,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) {