From 185dddd8c747f33d8c5f2e10f348015dcd655d16 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Thu, 24 Mar 2022 07:40:03 +0900 Subject: [PATCH] Truncate hashrates after #1435 - Fix hashrate indexing logs --- backend/src/api/database-migration.ts | 7 ++++++- backend/src/api/mining.ts | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/src/api/database-migration.ts b/backend/src/api/database-migration.ts index ffa9041e3..20519cbf2 100644 --- a/backend/src/api/database-migration.ts +++ b/backend/src/api/database-migration.ts @@ -6,7 +6,7 @@ import logger from '../logger'; const sleep = (ms: number) => new Promise(res => setTimeout(res, ms)); class DatabaseMigration { - private static currentVersion = 15; + private static currentVersion = 16; private queryTimeout = 120000; private statisticsAddedIndexed = false; @@ -175,6 +175,11 @@ class DatabaseMigration { await this.$executeQuery(connection, 'ALTER TABLE `hashrates` MODIFY `pool_id` SMALLINT UNSIGNED NOT NULL DEFAULT "0"'); } + if (databaseSchemaVersion < 16 && isBitcoin === true) { + logger.warn(`'hashrates' table has been truncated. Re-indexing from scratch.`); + await this.$executeQuery(connection, 'TRUNCATE hashrates;'); // Need to re-index because we changed timestamps + } + connection.release(); } catch (e) { connection.release(); diff --git a/backend/src/api/mining.ts b/backend/src/api/mining.ts index 75fea9768..35884efb3 100644 --- a/backend/src/api/mining.ts +++ b/backend/src/api/mining.ts @@ -154,7 +154,7 @@ class Mining { await HashratesRepository.$saveHashrates(hashrates); hashrates.length = 0; - const elapsedSeconds = Math.max(1, Math.round((new Date().getTime()) - startedAt)); + const elapsedSeconds = Math.max(1, Math.round((new Date().getTime()) - startedAt)) / 1000; if (elapsedSeconds > 1) { const weeksPerSeconds = (indexedThisRun / elapsedSeconds).toFixed(2); const formattedDate = new Date(fromTimestamp).toUTCString(); @@ -244,7 +244,7 @@ class Mining { hashrates.length = 0; } - const elapsedSeconds = Math.max(1, Math.round(new Date().getTime() - startedAt)); + const elapsedSeconds = Math.max(1, Math.round(new Date().getTime() - startedAt)) / 1000; if (elapsedSeconds > 1) { const daysPerSeconds = (indexedThisRun / elapsedSeconds).toFixed(2); const formattedDate = new Date(fromTimestamp).toUTCString();