Cache live user agent report off request path

This commit is contained in:
Ben
2026-06-07 22:58:00 -04:00
parent f14d76c2ea
commit eac0fe65ab
2 changed files with 68 additions and 2 deletions
+24
View File
@@ -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;
}
}
}