Merge pull request #2259 from mempool/nymkappa/bugfix/unique-lightning-stats
Make sure lightning stats are not duplicated in db
This commit is contained in:
commit
3b1d4ffe43
@ -4,7 +4,7 @@ import logger from '../logger';
|
|||||||
import { Common } from './common';
|
import { Common } from './common';
|
||||||
|
|
||||||
class DatabaseMigration {
|
class DatabaseMigration {
|
||||||
private static currentVersion = 34;
|
private static currentVersion = 35;
|
||||||
private queryTimeout = 120000;
|
private queryTimeout = 120000;
|
||||||
private statisticsAddedIndexed = false;
|
private statisticsAddedIndexed = false;
|
||||||
private uniqueLogs: string[] = [];
|
private uniqueLogs: string[] = [];
|
||||||
@ -315,6 +315,11 @@ class DatabaseMigration {
|
|||||||
if (databaseSchemaVersion < 34 && isBitcoin == true) {
|
if (databaseSchemaVersion < 34 && isBitcoin == true) {
|
||||||
await this.$executeQuery('ALTER TABLE `lightning_stats` ADD clearnet_tor_nodes int(11) NOT NULL DEFAULT "0"');
|
await this.$executeQuery('ALTER TABLE `lightning_stats` ADD clearnet_tor_nodes int(11) NOT NULL DEFAULT "0"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (databaseSchemaVersion < 35 && isBitcoin == true) {
|
||||||
|
await this.$executeQuery('DELETE from `lightning_stats` WHERE added > "2021-09-19"');
|
||||||
|
await this.$executeQuery('ALTER TABLE `lightning_stats` ADD CONSTRAINT added_unique UNIQUE (added);');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,8 +8,8 @@ class LightningStatsUpdater {
|
|||||||
public async $startService(): Promise<void> {
|
public async $startService(): Promise<void> {
|
||||||
logger.info('Starting Lightning Stats service');
|
logger.info('Starting Lightning Stats service');
|
||||||
|
|
||||||
// LightningStatsImporter.$run();
|
await this.$runTasks();
|
||||||
this.$runTasks();
|
LightningStatsImporter.$run();
|
||||||
}
|
}
|
||||||
|
|
||||||
private setDateMidnight(date: Date): void {
|
private setDateMidnight(date: Date): void {
|
||||||
@ -35,7 +35,7 @@ class LightningStatsUpdater {
|
|||||||
this.setDateMidnight(date);
|
this.setDateMidnight(date);
|
||||||
date.setUTCHours(24);
|
date.setUTCHours(24);
|
||||||
|
|
||||||
logger.info(`Updating latest node stats`);
|
logger.info(`Updating latest networks stats`);
|
||||||
const networkGraph = await lightningApi.$getNetworkGraph();
|
const networkGraph = await lightningApi.$getNetworkGraph();
|
||||||
LightningStatsImporter.computeNetworkStats(date.getTime() / 1000, networkGraph);
|
LightningStatsImporter.computeNetworkStats(date.getTime() / 1000, networkGraph);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user