From 2ef2a34766a031c71b24d690b3d9be186b5827fa Mon Sep 17 00:00:00 2001 From: nymkappa Date: Sat, 2 Apr 2022 23:29:37 +0900 Subject: [PATCH 1/2] Avoid parralel hashrate indexing when initial query is too slow --- backend/src/api/mining.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/src/api/mining.ts b/backend/src/api/mining.ts index 7e15c85d0..a3246f36f 100644 --- a/backend/src/api/mining.ts +++ b/backend/src/api/mining.ts @@ -86,16 +86,17 @@ class Mining { return; } + this.weeklyHashrateIndexingStarted = true; + // We only run this once a week const latestTimestamp = await HashratesRepository.$getLatestRunTimestamp('last_weekly_hashrates_indexing') * 1000; const now = new Date(); if (now.getTime() - latestTimestamp < 604800000) { + this.weeklyHashrateIndexingStarted = false; return; } try { - this.weeklyHashrateIndexingStarted = true; - logger.info(`Indexing mining pools weekly hashrates`); const indexedTimestamp = await HashratesRepository.$getWeeklyHashrateTimestamps(); @@ -186,16 +187,17 @@ class Mining { return; } + this.hashrateIndexingStarted = true; + // We only run this once a day const latestTimestamp = await HashratesRepository.$getLatestRunTimestamp('last_hashrates_indexing') * 1000; const now = new Date().getTime(); if (now - latestTimestamp < 86400000) { + this.hashrateIndexingStarted = false; return; } try { - this.hashrateIndexingStarted = true; - logger.info(`Indexing network daily hashrate`); const indexedTimestamp = (await HashratesRepository.$getNetworkDailyHashrate(null)).map(hashrate => hashrate.timestamp); From f393cb08390b955d6edb2f1b3b80d16de93d0669 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Sat, 2 Apr 2022 23:44:07 +0900 Subject: [PATCH 2/2] Wrap initial query in try/catch to reset the flag upon error --- backend/src/api/mining.ts | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/backend/src/api/mining.ts b/backend/src/api/mining.ts index a3246f36f..db69b7621 100644 --- a/backend/src/api/mining.ts +++ b/backend/src/api/mining.ts @@ -86,14 +86,20 @@ class Mining { return; } - this.weeklyHashrateIndexingStarted = true; - - // We only run this once a week - const latestTimestamp = await HashratesRepository.$getLatestRunTimestamp('last_weekly_hashrates_indexing') * 1000; const now = new Date(); - if (now.getTime() - latestTimestamp < 604800000) { + + try { + this.weeklyHashrateIndexingStarted = true; + + // We only run this once a week + const latestTimestamp = await HashratesRepository.$getLatestRunTimestamp('last_weekly_hashrates_indexing') * 1000; + if (now.getTime() - latestTimestamp < 604800000) { + this.weeklyHashrateIndexingStarted = false; + return; + } + } catch (e) { this.weeklyHashrateIndexingStarted = false; - return; + throw e; } try { @@ -187,14 +193,20 @@ class Mining { return; } - this.hashrateIndexingStarted = true; - - // We only run this once a day - const latestTimestamp = await HashratesRepository.$getLatestRunTimestamp('last_hashrates_indexing') * 1000; const now = new Date().getTime(); - if (now - latestTimestamp < 86400000) { + + try { + this.hashrateIndexingStarted = true; + + // We only run this once a day + const latestTimestamp = await HashratesRepository.$getLatestRunTimestamp('last_hashrates_indexing') * 1000; + if (now - latestTimestamp < 86400000) { + this.hashrateIndexingStarted = false; + return; + } + } catch (e) { this.hashrateIndexingStarted = false; - return; + throw e; } try {