optimized share calculation and updating

This commit is contained in:
Ben Wilson
2024-02-17 18:22:09 -05:00
parent d486c778a3
commit e35bacc648
9 changed files with 161 additions and 84 deletions
+15
View File
@@ -25,4 +25,19 @@ export class RpcBlockService {
public saveBlock(blockHeight: number, data: string) {
return this.rpcBlockRepository.update(blockHeight, { data })
}
public async deleteOldBlocks() {
const result = await this.rpcBlockRepository.createQueryBuilder('entity')
.select('MAX(entity.blockHeight)', 'maxNumber')
.getRawOne();
const newestBlock = result ? result.maxNumber : null;
await this.rpcBlockRepository.createQueryBuilder()
.delete()
.where('"blockHeight" < :newestBlock', { newestBlock })
.execute();
return;
}
}