mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
Count only working clients in miner report
This commit is contained in:
@@ -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<void> {
|
||||
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<void> {
|
||||
await queryRunner.query(`DROP INDEX CONCURRENTLY IF EXISTS "IDX_client_working_report_updated_user_agent"`);
|
||||
}
|
||||
}
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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<UserAgentReportView>();
|
||||
|
||||
Reference in New Issue
Block a user