From fe91ffcc9dadedca0f6eb002c86734e3cc631b65 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 13 Oct 2024 00:51:55 +0800 Subject: [PATCH] wip --- server/jobs/clear-old-data.js | 3 ++ server/uptime-calculator.js | 55 ++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/server/jobs/clear-old-data.js b/server/jobs/clear-old-data.js index 956be10e7..fcdeac187 100644 --- a/server/jobs/clear-old-data.js +++ b/server/jobs/clear-old-data.js @@ -13,6 +13,9 @@ const DEFAULT_KEEP_PERIOD = 180; const clearOldData = async () => { + // TODO: Temporary disable for testing + return; + /* * TODO: * Since we have aggregated table now, we don't need so much data in heartbeat table. diff --git a/server/uptime-calculator.js b/server/uptime-calculator.js index 5b27fe6fb..916f4c4cc 100644 --- a/server/uptime-calculator.js +++ b/server/uptime-calculator.js @@ -305,37 +305,40 @@ class UptimeCalculator { } await R.store(dailyStatBean); - let hourlyStatBean = await this.getHourlyStatBean(hourlyKey); - hourlyStatBean.up = hourlyData.up; - hourlyStatBean.down = hourlyData.down; - hourlyStatBean.ping = hourlyData.avgPing; - hourlyStatBean.pingMin = hourlyData.minPing; - hourlyStatBean.pingMax = hourlyData.maxPing; - { - // eslint-disable-next-line no-unused-vars - const { up, down, avgPing, minPing, maxPing, timestamp, ...extras } = hourlyData; - if (Object.keys(extras).length > 0) { - hourlyStatBean.extras = JSON.stringify(extras); + // TODO: For migration mode, we don't need to store old hourly and minutely data, but we need 24-hour's minutely data and 30-day's hourly data + if (false) { + let hourlyStatBean = await this.getHourlyStatBean(hourlyKey); + hourlyStatBean.up = hourlyData.up; + hourlyStatBean.down = hourlyData.down; + hourlyStatBean.ping = hourlyData.avgPing; + hourlyStatBean.pingMin = hourlyData.minPing; + hourlyStatBean.pingMax = hourlyData.maxPing; + { + // eslint-disable-next-line no-unused-vars + const { up, down, avgPing, minPing, maxPing, timestamp, ...extras } = hourlyData; + if (Object.keys(extras).length > 0) { + hourlyStatBean.extras = JSON.stringify(extras); + } } - } - await R.store(hourlyStatBean); + await R.store(hourlyStatBean); - let minutelyStatBean = await this.getMinutelyStatBean(divisionKey); - minutelyStatBean.up = minutelyData.up; - minutelyStatBean.down = minutelyData.down; - minutelyStatBean.ping = minutelyData.avgPing; - minutelyStatBean.pingMin = minutelyData.minPing; - minutelyStatBean.pingMax = minutelyData.maxPing; - { - // eslint-disable-next-line no-unused-vars - const { up, down, avgPing, minPing, maxPing, timestamp, ...extras } = minutelyData; - if (Object.keys(extras).length > 0) { - minutelyStatBean.extras = JSON.stringify(extras); + let minutelyStatBean = await this.getMinutelyStatBean(divisionKey); + minutelyStatBean.up = minutelyData.up; + minutelyStatBean.down = minutelyData.down; + minutelyStatBean.ping = minutelyData.avgPing; + minutelyStatBean.pingMin = minutelyData.minPing; + minutelyStatBean.pingMax = minutelyData.maxPing; + { + // eslint-disable-next-line no-unused-vars + const { up, down, avgPing, minPing, maxPing, timestamp, ...extras } = minutelyData; + if (Object.keys(extras).length > 0) { + minutelyStatBean.extras = JSON.stringify(extras); + } } + await R.store(minutelyStatBean); } - await R.store(minutelyStatBean); - // TODO: it seems that it is also necessary to remove the old data in the migration mode + // No need to remove old data in migration mode if (!this.migrationMode) { // Remove the old data log.debug("uptime-calc", "Remove old data");