mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 17:15:03 -07:00
Cache pool accounting summary
This commit is contained in:
@@ -3,15 +3,18 @@ import { Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import { UserAgentReportService } from '../ORM/_views/user-agent-report/user-agent-report.service';
|
||||
import { ClientService } from '../ORM/client/client.service';
|
||||
import { RpcBlockService } from '../ORM/rpc-block/rpc-block.service';
|
||||
import { ShareAccountingService } from '../ORM/share-accounting/share-accounting.service';
|
||||
|
||||
@Injectable()
|
||||
export class AppService implements OnModuleInit {
|
||||
private refreshingLiveUserAgentReport = false;
|
||||
private refreshingPoolSummary = false;
|
||||
|
||||
constructor(
|
||||
private readonly clientService: ClientService,
|
||||
private readonly rpcBlockService: RpcBlockService,
|
||||
private readonly userAgentReportService: UserAgentReportService
|
||||
private readonly userAgentReportService: UserAgentReportService,
|
||||
private readonly shareAccountingService: ShareAccountingService
|
||||
) {
|
||||
|
||||
}
|
||||
@@ -30,10 +33,12 @@ export class AppService implements OnModuleInit {
|
||||
|
||||
setInterval(async () => {
|
||||
await this.refreshLiveUserAgentReport();
|
||||
await this.refreshPoolSummary();
|
||||
}, 1000 * 30);
|
||||
|
||||
setTimeout(async () => {
|
||||
await this.refreshLiveUserAgentReport();
|
||||
await this.refreshPoolSummary();
|
||||
}, 1000 * 15);
|
||||
|
||||
setInterval(async () => {
|
||||
@@ -67,4 +72,19 @@ export class AppService implements OnModuleInit {
|
||||
this.refreshingLiveUserAgentReport = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async refreshPoolSummary() {
|
||||
if (this.refreshingPoolSummary) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.refreshingPoolSummary = true;
|
||||
try {
|
||||
await this.shareAccountingService.refreshPoolSummary();
|
||||
} catch (error) {
|
||||
console.error(`Failed refreshing pool accounting summary: ${error.message}`);
|
||||
} finally {
|
||||
this.refreshingPoolSummary = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user