mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
Avoid client accounting queries in API workers
This commit is contained in:
@@ -159,7 +159,7 @@ export class ShareAccountingService implements OnModuleDestroy {
|
||||
return summary;
|
||||
}
|
||||
|
||||
private emptySummary(): ShareAccountingSummary {
|
||||
public emptySummary(): ShareAccountingSummary {
|
||||
return {
|
||||
totalAcceptedShares: 0,
|
||||
totalCreditedDifficulty: 0,
|
||||
@@ -193,7 +193,7 @@ export class ShareAccountingService implements OnModuleDestroy {
|
||||
public async getSessionSummaries(clientIds: string[]): Promise<Map<string, SessionShareSummary>> {
|
||||
const uniqueClientIds = [...new Set(clientIds.filter(clientId => clientId != null))];
|
||||
const summaries = new Map<string, SessionShareSummary>();
|
||||
if (uniqueClientIds.length === 0) {
|
||||
if (uniqueClientIds.length === 0 || process.env.API_ONLY === 'true') {
|
||||
return summaries;
|
||||
}
|
||||
|
||||
@@ -222,6 +222,10 @@ export class ShareAccountingService implements OnModuleDestroy {
|
||||
}
|
||||
|
||||
private async getSummary(filter: AccountingFilter): Promise<ShareAccountingSummary> {
|
||||
if (process.env.API_ONLY === 'true') {
|
||||
return this.emptySummary();
|
||||
}
|
||||
|
||||
const cacheKey = this.getSummaryCacheKey(filter);
|
||||
const cached = this.summaryCache.get(cacheKey);
|
||||
const now = Date.now();
|
||||
|
||||
@@ -27,11 +27,16 @@ export class ClientController {
|
||||
const workers = await timeAsync('/api/client/:address presence', () => this.redisMessagingService.getClientPresenceByAddress(address), { address });
|
||||
const sessionSummaries = await timeAsync('/api/client/:address session summaries', () => this.shareAccountingService.getSessionSummaries(workers.map(worker => worker.clientId)), { address, workers: workers.length });
|
||||
|
||||
const addressSettings = await timeAsync('/api/client/:address address settings', () => this.addressSettingsService.getSettings(address, false), { address });
|
||||
const addressSettings = process.env.API_ONLY === 'true'
|
||||
? null
|
||||
: await timeAsync('/api/client/:address address settings', () => this.addressSettingsService.getSettings(address, false), { address });
|
||||
const accounting = await timeAsync('/api/client/:address accounting', () => this.shareAccountingService.getAddressSummary(address), { address });
|
||||
const bestDifficulty = addressSettings?.bestDifficulty ?? workers.reduce((best, worker) => {
|
||||
return Math.max(best, Number(worker.bestDifficulty ?? 0));
|
||||
}, 0);
|
||||
|
||||
const response = {
|
||||
bestDifficulty: addressSettings?.bestDifficulty,
|
||||
bestDifficulty,
|
||||
workersCount: workers.length,
|
||||
accounting,
|
||||
workers: await Promise.all(
|
||||
|
||||
Reference in New Issue
Block a user