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 } = {};
|
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[] {
|
public getMempoolBlocks(): MempoolBlock[] {
|
||||||
return this.mempoolBlocks.map((block) => {
|
return this.mempoolBlocks.map((block) => {
|
||||||
return {
|
return {
|
||||||
@ -54,6 +45,14 @@ class MempoolBlocks {
|
|||||||
return this.mempoolBlockDeltas;
|
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[] {
|
private calculateMempoolDeltas(prevBlocks: MempoolBlockWithTransactions[], mempoolBlocks: MempoolBlockWithTransactions[]): MempoolBlockDelta[] {
|
||||||
const mempoolBlockDeltas: MempoolBlockDelta[] = [];
|
const mempoolBlockDeltas: MempoolBlockDelta[] = [];
|
||||||
for (let i = 0; i < Math.max(mempoolBlocks.length, prevBlocks.length); i++) {
|
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 path from 'path';
|
||||||
import config from './config';
|
import config from './config';
|
||||||
import { createPool, Pool, PoolConnection } from 'mysql2/promise';
|
import { createPool, Pool, PoolConnection } from 'mysql2/promise';
|
||||||
import { LogLevel } from './logger';
|
import logger, { LogLevel } from './logger';
|
||||||
import logger from './logger';
|
|
||||||
import { FieldPacket, OkPacket, PoolOptions, ResultSetHeader, RowDataPacket } from 'mysql2/typings/mysql';
|
import { FieldPacket, OkPacket, PoolOptions, ResultSetHeader, RowDataPacket } from 'mysql2/typings/mysql';
|
||||||
import { execSync } from 'child_process';
|
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 bitcoinSecondClient from './api/bitcoin/bitcoin-second-client';
|
||||||
import accelerationRoutes from './api/acceleration/acceleration.routes';
|
import accelerationRoutes from './api/acceleration/acceleration.routes';
|
||||||
import aboutRoutes from './api/about.routes';
|
import aboutRoutes from './api/about.routes';
|
||||||
|
import mempoolBlocks from './api/mempool-blocks';
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
private wss: WebSocket.Server | undefined;
|
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 poolsUpdater.updatePoolsJson(); // Needs to be done before loading the disk cache because we sometimes wipe it
|
||||||
await syncAssets.syncAssets$();
|
await syncAssets.syncAssets$();
|
||||||
|
await mempoolBlocks.updatePools$();
|
||||||
if (config.MEMPOOL.ENABLED) {
|
if (config.MEMPOOL.ENABLED) {
|
||||||
if (config.MEMPOOL.CACHE_ENABLED) {
|
if (config.MEMPOOL.CACHE_ENABLED) {
|
||||||
await diskCache.$loadMempoolCache();
|
await diskCache.$loadMempoolCache();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user