separate home graph into it's own table

This commit is contained in:
Ben Wilson
2024-01-16 19:37:29 -05:00
parent bbc14e2272
commit 6bc42defef
8 changed files with 173 additions and 5 deletions
+46 -1
View File
@@ -4,6 +4,8 @@ import { DataSource } from 'typeorm';
import { ClientStatisticsService } from '../ORM/client-statistics/client-statistics.service';
import { ClientService } from '../ORM/client/client.service';
import { HomeGraphService } from '../ORM/home-graph/home-graph.service';
import { RpcBlockService } from '../ORM/rpc-block/rpc-block.service';
@Injectable()
export class AppService implements OnModuleInit {
@@ -11,7 +13,9 @@ export class AppService implements OnModuleInit {
constructor(
private readonly clientStatisticsService: ClientStatisticsService,
private readonly clientService: ClientService,
private readonly dataSource: DataSource
private readonly rpcBlockService: RpcBlockService,
private readonly homeGraphService: HomeGraphService,
private readonly dataSource: DataSource,
) {
}
@@ -39,4 +43,45 @@ export class AppService implements OnModuleInit {
}
}
@Interval(1000 * 60 * 60 * 24)
private async deleteOldBlocks() {
console.log('Deleting Old Blocks');
if (process.env.ENABLE_SOLO == 'true' && (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0')) {
await this.rpcBlockService.deleteOldBlocks();
}
}
@Interval(1000 * 60 * 10)
private async updateChart() {
console.log('Updating Chart');
const latestGraphUpdate = await this.homeGraphService.getLatestTime();
const data = await this.dataSource.query(`
SELECT
time AS label,
ROUND(((SUM(shares) * 4294967296) / 600)) AS data
FROM
client_statistics_entity AS entry
WHERE
entry.time > ${latestGraphUpdate.getTime()}
GROUP BY
time
ORDER BY
time
LIMIT 144;
`)
console.log(`Fetched ${data.length} rows`);
if (data.length < 2) {
return;
}
const result = data.slice(0, data.length - 1);
this.homeGraphService.save(result);
}
}