Avoid raw pool summary on API process

This commit is contained in:
Ben
2026-06-07 23:13:14 -04:00
parent 96e0e36755
commit 13106347b2
2 changed files with 28 additions and 2 deletions
@@ -140,19 +140,42 @@ export class ShareAccountingService implements OnModuleDestroy {
return cached;
}
if (process.env.API_ONLY === 'true') {
return this.emptySummary();
}
return this.getSummary({});
}
public async refreshPoolSummary(): Promise<ShareAccountingSummary> {
const summary = await this.getSummary({});
await this.redisMessagingService
?.setJsonCache(this.poolSummaryCacheKey, summary, 60 * 1000)
?.setJsonCache(this.poolSummaryCacheKey, summary, 10 * 60 * 1000)
.catch(error => {
console.error(`Pool accounting summary cache write failed: ${error.message}`);
});
return summary;
}
private emptySummary(): ShareAccountingSummary {
return {
totalAcceptedShares: 0,
totalCreditedDifficulty: 0,
acceptedSharesLast10Minutes: 0,
creditedDifficultyLast10Minutes: 0,
acceptedSharesLastHour: 0,
creditedDifficultyLastHour: 0,
acceptedSharesLastDay: 0,
creditedDifficultyLastDay: 0,
hashRateLast10Minutes: 0,
hashRateLastHour: 0,
bestSubmissionDifficulty: 0,
blockCandidateCount: 0,
latestShareAt: null,
protocolBreakdown: [],
};
}
public async getAddressSummary(address: string): Promise<ShareAccountingSummary> {
return this.getSummary({ address });
}
+4 -1
View File
@@ -33,7 +33,6 @@ export class AppService implements OnModuleInit {
setInterval(async () => {
await this.refreshLiveUserAgentReport();
await this.refreshPoolSummary();
}, 1000 * 30);
setTimeout(async () => {
@@ -41,6 +40,10 @@ export class AppService implements OnModuleInit {
await this.refreshPoolSummary();
}, 1000 * 15);
setInterval(async () => {
await this.refreshPoolSummary();
}, 1000 * 60 * 5);
setInterval(async () => {
console.log('Refreshing user agent report view')
await this.userAgentReportService.refreshReport();