From ba61a540daa5181cb0f1d4beb93ad3914491b20d Mon Sep 17 00:00:00 2001 From: XuJiacheng Date: Tue, 3 Mar 2026 20:21:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E6=88=96=E6=9C=AA=E6=9D=A5=E6=97=A5=E6=9C=9F=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BB=A5=E4=BC=98=E5=8C=96=E5=88=86=E5=8C=BA?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bls-onoffline-backend/dist/index.js | 13 +++++++++++-- bls-onoffline-backend/src/db/partitionManager.js | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/bls-onoffline-backend/dist/index.js b/bls-onoffline-backend/dist/index.js index ab89c16..c43a110 100644 --- a/bls-onoffline-backend/dist/index.js +++ b/bls-onoffline-backend/dist/index.js @@ -174,6 +174,13 @@ class DatabaseManager { } const dbManager = new DatabaseManager(config.db); class PartitionManager { + isCurrentOrFutureDate(date) { + const normalizedDate = new Date(date); + normalizedDate.setHours(0, 0, 0, 0); + const today = /* @__PURE__ */ new Date(); + today.setHours(0, 0, 0, 0); + return normalizedDate.getTime() >= today.getTime(); + } /** * Calculate the start and end timestamps (milliseconds) for a given date. * @param {Date} date - The date to calculate for. @@ -218,10 +225,11 @@ class PartitionManager { if (!checkRes.rows[0].exists) { logger.info(`Creating partition ${partitionName} for range [${startMs}, ${endMs})`); console.log(`Creating partition ${partitionName} for range [${startMs}, ${endMs})`); + const tablespaceClause = this.isCurrentOrFutureDate(targetDate) ? " TABLESPACE ts_hot" : ""; const createSql = ` CREATE TABLE IF NOT EXISTS ${partitionName} PARTITION OF ${schema}.${table} - FOR VALUES FROM (${startMs}) TO (${endMs}); + FOR VALUES FROM (${startMs}) TO (${endMs})${tablespaceClause}; `; await client.query(createSql); } @@ -263,10 +271,11 @@ class PartitionManager { const checkRes = await client.query(`SELECT to_regclass($1) as exists;`, [partitionName]); if (!checkRes.rows[0].exists) { logger.info(`Creating partition ${partitionName} for range [${startMs}, ${endMs})`); + const tablespaceClause = this.isCurrentOrFutureDate(targetDate) ? " TABLESPACE ts_hot" : ""; await client.query(` CREATE TABLE IF NOT EXISTS ${partitionName} PARTITION OF ${schema}.${table} - FOR VALUES FROM (${startMs}) TO (${endMs}); + FOR VALUES FROM (${startMs}) TO (${endMs})${tablespaceClause}; `); } } diff --git a/bls-onoffline-backend/src/db/partitionManager.js b/bls-onoffline-backend/src/db/partitionManager.js index a28d029..7a3651e 100644 --- a/bls-onoffline-backend/src/db/partitionManager.js +++ b/bls-onoffline-backend/src/db/partitionManager.js @@ -3,6 +3,16 @@ import { config } from '../config/config.js'; import dbManager from './databaseManager.js'; class PartitionManager { + isCurrentOrFutureDate(date) { + const normalizedDate = new Date(date); + normalizedDate.setHours(0, 0, 0, 0); + + const today = new Date(); + today.setHours(0, 0, 0, 0); + + return normalizedDate.getTime() >= today.getTime(); + } + /** * Calculate the start and end timestamps (milliseconds) for a given date. * @param {Date} date - The date to calculate for. @@ -56,10 +66,11 @@ class PartitionManager { if (!checkRes.rows[0].exists) { logger.info(`Creating partition ${partitionName} for range [${startMs}, ${endMs})`); console.log(`Creating partition ${partitionName} for range [${startMs}, ${endMs})`); + const tablespaceClause = this.isCurrentOrFutureDate(targetDate) ? ' TABLESPACE ts_hot' : ''; const createSql = ` CREATE TABLE IF NOT EXISTS ${partitionName} PARTITION OF ${schema}.${table} - FOR VALUES FROM (${startMs}) TO (${endMs}); + FOR VALUES FROM (${startMs}) TO (${endMs})${tablespaceClause}; `; await client.query(createSql); } @@ -108,10 +119,11 @@ class PartitionManager { const checkRes = await client.query(`SELECT to_regclass($1) as exists;`, [partitionName]); if (!checkRes.rows[0].exists) { logger.info(`Creating partition ${partitionName} for range [${startMs}, ${endMs})`); + const tablespaceClause = this.isCurrentOrFutureDate(targetDate) ? ' TABLESPACE ts_hot' : ''; await client.query(` CREATE TABLE IF NOT EXISTS ${partitionName} PARTITION OF ${schema}.${table} - FOR VALUES FROM (${startMs}) TO (${endMs}); + FOR VALUES FROM (${startMs}) TO (${endMs})${tablespaceClause}; `); } }