mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
statistics saving
This commit is contained in:
@@ -18,20 +18,16 @@ export class ClientStatisticsService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async save(clientStatistic: Partial<ClientStatisticsEntity>) {
|
public async update(clientStatistic: Partial<ClientStatisticsEntity>) {
|
||||||
// // Attempt to update the existing record
|
|
||||||
const result = await this.clientStatisticsRepository.update({ clientId: clientStatistic.clientId, time: clientStatistic.time },
|
await this.clientStatisticsRepository.update({ clientId: clientStatistic.clientId, time: clientStatistic.time },
|
||||||
{
|
{
|
||||||
shares: clientStatistic.shares,
|
shares: clientStatistic.shares,
|
||||||
acceptedCount: clientStatistic.acceptedCount
|
acceptedCount: clientStatistic.acceptedCount
|
||||||
})
|
})
|
||||||
|
}
|
||||||
// Check if the update affected any rows
|
public async insert(clientStatistic: Partial<ClientStatisticsEntity>) {
|
||||||
if (result.affected === 0) {
|
await this.clientStatisticsRepository.insert(clientStatistic);
|
||||||
// If no rows were updated, insert a new record
|
|
||||||
await this.clientStatisticsRepository.insert(clientStatistic);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteOldStatistics() {
|
public async deleteOldStatistics() {
|
||||||
|
|||||||
@@ -22,25 +22,6 @@ export class StratumV1ClientStatistics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async saveShares(client: ClientEntity) {
|
|
||||||
|
|
||||||
// if (client == null || client.address == null || client.clientName == null || client.sessionId == null) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
await this.clientStatisticsService.save({
|
|
||||||
time: this.currentTimeSlot,
|
|
||||||
clientId: client.id,
|
|
||||||
shares: this.shares,
|
|
||||||
acceptedCount: this.acceptedCount,
|
|
||||||
address: client.address,
|
|
||||||
clientName: client.clientName,
|
|
||||||
sessionId: client.sessionId
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// We don't want to save them here because it can be DB intensive, instead do it every once in
|
// We don't want to save them here because it can be DB intensive, instead do it every once in
|
||||||
// awhile with saveShares()
|
// awhile with saveShares()
|
||||||
@@ -66,12 +47,28 @@ export class StratumV1ClientStatistics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.currentTimeSlot != timeSlot) {
|
if (this.currentTimeSlot != timeSlot) {
|
||||||
await this.saveShares(client);
|
await this.clientStatisticsService.insert({
|
||||||
|
time: this.currentTimeSlot,
|
||||||
|
clientId: client.id,
|
||||||
|
shares: this.shares,
|
||||||
|
acceptedCount: this.acceptedCount,
|
||||||
|
address: client.address,
|
||||||
|
clientName: client.clientName,
|
||||||
|
sessionId: client.sessionId
|
||||||
|
});
|
||||||
this.shares = 0;
|
this.shares = 0;
|
||||||
this.acceptedCount = 0;
|
this.acceptedCount = 0;
|
||||||
this.currentTimeSlot = timeSlot;
|
this.currentTimeSlot = timeSlot;
|
||||||
} else if ((date.getTime() - 60 * 1000) > this.lastSave) {
|
} else if ((date.getTime() - 60 * 1000) > this.lastSave) {
|
||||||
await this.saveShares(client);
|
await this.clientStatisticsService.update({
|
||||||
|
time: this.currentTimeSlot,
|
||||||
|
clientId: client.id,
|
||||||
|
shares: this.shares,
|
||||||
|
acceptedCount: this.acceptedCount,
|
||||||
|
address: client.address,
|
||||||
|
clientName: client.clientName,
|
||||||
|
sessionId: client.sessionId
|
||||||
|
});
|
||||||
this.lastSave = new Date().getTime();
|
this.lastSave = new Date().getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user