mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 17:15:03 -07:00
Cache live user agent report off request path
This commit is contained in:
@@ -6,6 +6,7 @@ import { RpcBlockService } from '../ORM/rpc-block/rpc-block.service';
|
||||
|
||||
@Injectable()
|
||||
export class AppService implements OnModuleInit {
|
||||
private refreshingLiveUserAgentReport = false;
|
||||
|
||||
constructor(
|
||||
private readonly clientService: ClientService,
|
||||
@@ -27,6 +28,14 @@ export class AppService implements OnModuleInit {
|
||||
await this.rpcBlockService.deleteOldBlocks();
|
||||
}, 1000 * 60 * 60 * 24);
|
||||
|
||||
setInterval(async () => {
|
||||
await this.refreshLiveUserAgentReport();
|
||||
}, 1000 * 30);
|
||||
|
||||
setTimeout(async () => {
|
||||
await this.refreshLiveUserAgentReport();
|
||||
}, 1000 * 15);
|
||||
|
||||
setInterval(async () => {
|
||||
console.log('Refreshing user agent report view')
|
||||
await this.userAgentReportService.refreshReport();
|
||||
@@ -43,4 +52,19 @@ export class AppService implements OnModuleInit {
|
||||
console.log(`Deleted ${deletedClients.affected} old clients`);
|
||||
|
||||
}
|
||||
|
||||
private async refreshLiveUserAgentReport() {
|
||||
if (this.refreshingLiveUserAgentReport) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.refreshingLiveUserAgentReport = true;
|
||||
try {
|
||||
await this.userAgentReportService.refreshLiveReport();
|
||||
} catch (error) {
|
||||
console.error(`Failed refreshing live user agent report: ${error.message}`);
|
||||
} finally {
|
||||
this.refreshingLiveUserAgentReport = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user