diff --git a/src/ORM/share-accounting/share-accounting.service.ts b/src/ORM/share-accounting/share-accounting.service.ts index 542e8c6..2ccc2cf 100644 --- a/src/ORM/share-accounting/share-accounting.service.ts +++ b/src/ORM/share-accounting/share-accounting.service.ts @@ -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> { const uniqueClientIds = [...new Set(clientIds.filter(clientId => clientId != null))]; const summaries = new Map(); - 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 { + if (process.env.API_ONLY === 'true') { + return this.emptySummary(); + } + const cacheKey = this.getSummaryCacheKey(filter); const cached = this.summaryCache.get(cacheKey); const now = Date.now(); diff --git a/src/controllers/client/client.controller.ts b/src/controllers/client/client.controller.ts index e1be2e8..ef17041 100644 --- a/src/controllers/client/client.controller.ts +++ b/src/controllers/client/client.controller.ts @@ -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(