diff --git a/backend/src/index.ts b/backend/src/index.ts index b00909bc6..adb3f2e02 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -194,6 +194,7 @@ class Server { await memPool.$updateMempool(newMempool, pollRate); } indexer.$run(); + priceUpdater.$run(); // rerun immediately if we skipped the mempool update, otherwise wait POLL_RATE_MS const elapsed = Date.now() - start; diff --git a/backend/src/indexer.ts b/backend/src/indexer.ts index 7ec65d9c9..392174ecf 100644 --- a/backend/src/indexer.ts +++ b/backend/src/indexer.ts @@ -106,7 +106,7 @@ class Indexer { } try { - await priceUpdater.$run(); + await priceUpdater.$run(true); } catch (e) { logger.err(`Running priceUpdater failed. Reason: ` + (e instanceof Error ? e.message : e)); } diff --git a/backend/src/tasks/price-updater.ts b/backend/src/tasks/price-updater.ts index 91a36d04b..f96616c12 100644 --- a/backend/src/tasks/price-updater.ts +++ b/backend/src/tasks/price-updater.ts @@ -72,7 +72,7 @@ class PriceUpdater { this.latestPrices = await PricesRepository.$getLatestConversionRates(); } - public async $run(): Promise { + public async $run(storeInDb: boolean = false): Promise { if (config.MEMPOOL.NETWORK === 'signet' || config.MEMPOOL.NETWORK === 'testnet') { // Coins have no value on testnet/signet, so we want to always show 0 return; @@ -89,7 +89,7 @@ class PriceUpdater { } try { - await this.$updatePrice(); + await this.$updatePrice(storeInDb); if (this.historyInserted === false && config.DATABASE.ENABLED === true) { await this.$insertHistoricalPrices(); } @@ -103,7 +103,7 @@ class PriceUpdater { /** * Fetch last BTC price from exchanges, average them, and save it in the database once every hour */ - private async $updatePrice(): Promise { + private async $updatePrice(storeInDb: boolean): Promise { if (this.lastRun === 0 && config.DATABASE.ENABLED === true) { this.lastRun = await PricesRepository.$getLatestPriceTime(); } @@ -146,7 +146,7 @@ class PriceUpdater { } } - if (config.DATABASE.ENABLED === true) { + if (config.DATABASE.ENABLED === true && storeInDb) { // Save everything in db try { const p = 60 * 60 * 1000; // milliseconds in an hour