From bc8eba3c49cfec846a3bf2972faef03f75f65a5e Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 20 Jun 2026 23:54:40 -0400 Subject: [PATCH] Count only working clients in miner report --- .../ActiveClientReportIndex1781311000000.ts | 20 +++++++++++++++++++ .../user-agent-report.service.spec.ts | 1 + .../user-agent-report.service.ts | 1 + 3 files changed, 22 insertions(+) create mode 100644 src/ORM/_migrations/ActiveClientReportIndex1781311000000.ts diff --git a/src/ORM/_migrations/ActiveClientReportIndex1781311000000.ts b/src/ORM/_migrations/ActiveClientReportIndex1781311000000.ts new file mode 100644 index 0000000..87e958f --- /dev/null +++ b/src/ORM/_migrations/ActiveClientReportIndex1781311000000.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class ActiveClientReportIndex1781311000000 implements MigrationInterface { + public name = 'ActiveClientReportIndex1781311000000'; + public transaction = false; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + CREATE INDEX CONCURRENTLY IF NOT EXISTS "IDX_client_working_report_updated_user_agent" + ON "client_entity" ("updatedAt" DESC, "userAgent") + INCLUDE ("hashRate", "bestDifficulty") + WHERE "deletedAt" IS NULL + AND "hashRate" > 0 + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX CONCURRENTLY IF EXISTS "IDX_client_working_report_updated_user_agent"`); + } +} diff --git a/src/ORM/_views/user-agent-report/user-agent-report.service.spec.ts b/src/ORM/_views/user-agent-report/user-agent-report.service.spec.ts index cd9d664..2c2225d 100644 --- a/src/ORM/_views/user-agent-report/user-agent-report.service.spec.ts +++ b/src/ORM/_views/user-agent-report/user-agent-report.service.spec.ts @@ -55,6 +55,7 @@ describe('UserAgentReportService', () => { 'client.updatedAt > :activeSince', expect.objectContaining({ activeSince: expect.any(Date) }), ); + expect(clientRepository.queryBuilder.andWhere).toHaveBeenCalledWith('client.hashRate > 0'); }); it('falls back to the materialized view when no active database clients exist', async () => { diff --git a/src/ORM/_views/user-agent-report/user-agent-report.service.ts b/src/ORM/_views/user-agent-report/user-agent-report.service.ts index c494a3d..28d1e02 100644 --- a/src/ORM/_views/user-agent-report/user-agent-report.service.ts +++ b/src/ORM/_views/user-agent-report/user-agent-report.service.ts @@ -72,6 +72,7 @@ export class UserAgentReportService { .addSelect('COALESCE(SUM(client.hashRate), 0)', 'totalHashRate') .where('client.deletedAt IS NULL') .andWhere('client.updatedAt > :activeSince', { activeSince }) + .andWhere('client.hashRate > 0') .groupBy('COALESCE(NULLIF(client.userAgent, \'\'), \'Other\')') .orderBy('"totalHashRate"', 'DESC') .getRawMany();