mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 17:15:03 -07:00
cleanup and support for all address types
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
import { DateTimeTransformer } from '../utils/DateTimeTransformer';
|
||||
import { TrackedEntity } from '../utils/TrackedEntity.entity';
|
||||
@@ -15,9 +15,11 @@ export class ClientStatisticsEntity extends TrackedEntity {
|
||||
@Column()
|
||||
clientName: string;
|
||||
|
||||
@Index()
|
||||
@Column({ length: 8, type: 'varchar' })
|
||||
sessionId: string;
|
||||
|
||||
@Index()
|
||||
@Column({
|
||||
type: 'datetime',
|
||||
transformer: new DateTimeTransformer()
|
||||
|
||||
@@ -19,6 +19,17 @@ export class ClientStatisticsService {
|
||||
return await this.clientStatisticsRepository.save(clientStatistic);
|
||||
}
|
||||
|
||||
public async deleteOldStatistics() {
|
||||
const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
||||
|
||||
return await this.clientStatisticsRepository
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(ClientStatisticsEntity)
|
||||
.where('time < :time', { time: oneDayAgo })
|
||||
.execute();
|
||||
}
|
||||
|
||||
public async getHashRateForAddress(address: string) {
|
||||
|
||||
const query = `
|
||||
|
||||
@@ -25,6 +25,19 @@ export class ClientService {
|
||||
return await this.clientRepository.softDelete({ sessionId });
|
||||
}
|
||||
|
||||
public async deleteOldClients() {
|
||||
|
||||
const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
||||
|
||||
return await this.clientRepository
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(ClientEntity)
|
||||
.where('deletedAt < :time', { time: oneDayAgo })
|
||||
.execute();
|
||||
|
||||
}
|
||||
|
||||
public async updateBestDifficulty(sessionId: string, bestDifficulty: number) {
|
||||
return await this.clientRepository.update({ sessionId }, { bestDifficulty });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user