Defer db access to fix failing tests
This commit is contained in:
parent
9a838c7269
commit
42c60fd991
@ -24,15 +24,6 @@ class MempoolBlocks {
|
||||
|
||||
private pools: { [id: number]: PoolTag } = {};
|
||||
|
||||
constructor() {
|
||||
PoolsRepository.$getPools().then(allPools => {
|
||||
this.pools = {};
|
||||
for (const pool of allPools) {
|
||||
this.pools[pool.uniqueId] = pool;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public getMempoolBlocks(): MempoolBlock[] {
|
||||
return this.mempoolBlocks.map((block) => {
|
||||
return {
|
||||
@ -54,6 +45,14 @@ class MempoolBlocks {
|
||||
return this.mempoolBlockDeltas;
|
||||
}
|
||||
|
||||
public async updatePools$(): Promise<void> {
|
||||
const allPools = await PoolsRepository.$getPools();
|
||||
this.pools = {};
|
||||
for (const pool of allPools) {
|
||||
this.pools[pool.uniqueId] = pool;
|
||||
}
|
||||
}
|
||||
|
||||
private calculateMempoolDeltas(prevBlocks: MempoolBlockWithTransactions[], mempoolBlocks: MempoolBlockWithTransactions[]): MempoolBlockDelta[] {
|
||||
const mempoolBlockDeltas: MempoolBlockDelta[] = [];
|
||||
for (let i = 0; i < Math.max(mempoolBlocks.length, prevBlocks.length); i++) {
|
||||
|
@ -2,8 +2,7 @@ import * as fs from 'fs';
|
||||
import path from 'path';
|
||||
import config from './config';
|
||||
import { createPool, Pool, PoolConnection } from 'mysql2/promise';
|
||||
import { LogLevel } from './logger';
|
||||
import logger from './logger';
|
||||
import logger, { LogLevel } from './logger';
|
||||
import { FieldPacket, OkPacket, PoolOptions, ResultSetHeader, RowDataPacket } from 'mysql2/typings/mysql';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
|
@ -45,6 +45,7 @@ import bitcoinCoreRoutes from './api/bitcoin/bitcoin-core.routes';
|
||||
import bitcoinSecondClient from './api/bitcoin/bitcoin-second-client';
|
||||
import accelerationRoutes from './api/acceleration/acceleration.routes';
|
||||
import aboutRoutes from './api/about.routes';
|
||||
import mempoolBlocks from './api/mempool-blocks';
|
||||
|
||||
class Server {
|
||||
private wss: WebSocket.Server | undefined;
|
||||
@ -149,6 +150,7 @@ class Server {
|
||||
|
||||
await poolsUpdater.updatePoolsJson(); // Needs to be done before loading the disk cache because we sometimes wipe it
|
||||
await syncAssets.syncAssets$();
|
||||
await mempoolBlocks.updatePools$();
|
||||
if (config.MEMPOOL.ENABLED) {
|
||||
if (config.MEMPOOL.CACHE_ENABLED) {
|
||||
await diskCache.$loadMempoolCache();
|
||||
|
Loading…
x
Reference in New Issue
Block a user