From ee9ede9d7fe23261ab7e3a3a22170806c6f2311c Mon Sep 17 00:00:00 2001 From: Joshua Aruokhai Date: Mon, 14 Oct 2024 17:58:48 +0100 Subject: [PATCH] draft: improved operation state mechanism --- package-lock.json | 6 ------ package.json | 1 - src/app.module.ts | 14 ++++++-------- src/operation-state/operation-state.service.ts | 9 ++++----- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 939b69b..c13bdd6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,6 @@ "@nestjs/typeorm": "^10.0.2", "@nestjs/websockets": "^10.3.7", "axios": "^1.7.2", - "cron-validator": "^1.3.1", "currency.js": "^2.0.4", "js-yaml": "^4.1.0", "reflect-metadata": "^0.1.13", @@ -4660,11 +4659,6 @@ "luxon": "^3.2.1" } }, - "node_modules/cron-validator": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/cron-validator/-/cron-validator-1.3.1.tgz", - "integrity": "sha512-C1HsxuPCY/5opR55G5/WNzyEGDWFVG+6GLrA+fW/sCTcP6A6NTjUP2AK7B8n2PyFs90kDG2qzwm8LMheADku6A==" - }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", diff --git a/package.json b/package.json index 799eeff..31d8885 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,6 @@ "@nestjs/typeorm": "^10.0.2", "@nestjs/websockets": "^10.3.7", "axios": "^1.7.2", - "cron-validator": "^1.3.1", "currency.js": "^2.0.4", "js-yaml": "^4.1.0", "reflect-metadata": "^0.1.13", diff --git a/src/app.module.ts b/src/app.module.ts index 2eab9dd..623fc86 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -21,14 +21,12 @@ import { BlockProviderModule } from '@/block-data-providers/block-provider.modul TypeOrmModule.forRootAsync({ imports: [ConfigModule], inject: [ConfigService], - useFactory: (configService: ConfigService) => { - return { - type: 'sqlite', - database: configService.get('db.path'), - synchronize: configService.get('db.synchronize'), - autoLoadEntities: true, - }; - }, + useFactory: (configService: ConfigService) => ({ + type: 'sqlite', + database: configService.get('db.path'), + synchronize: configService.get('db.synchronize'), + autoLoadEntities: true, + }), }), TransactionsModule, SilentBlocksModule, diff --git a/src/operation-state/operation-state.service.ts b/src/operation-state/operation-state.service.ts index 41d860b..1f6a531 100644 --- a/src/operation-state/operation-state.service.ts +++ b/src/operation-state/operation-state.service.ts @@ -5,7 +5,7 @@ import { InjectRepository } from '@nestjs/typeorm'; @Injectable() export class OperationStateService { - private cacheSize = 2016; // Define the maximum queue size + private cacheSize = 2016; // Define the maximum cache size constructor( @InjectRepository(OperationState) @@ -16,7 +16,7 @@ export class OperationStateService { const state = ( await this.operationStateRepository.find({ order: { - indexedBlockHeight: 'DESC', // Get the newest item first + indexedBlockHeight: 'DESC', }, take: 1, }) @@ -36,7 +36,7 @@ export class OperationStateService { await this.trimState(); } - // Remove and return the oldest item in the queue + // Remove and return the oldest item in the state cache async dequeue_operation_state(): Promise { const latest_state = ( await this.operationStateRepository.find({ @@ -55,12 +55,11 @@ export class OperationStateService { return null; } - // Ensure the state size does not exceed the cache size private async trimState(): Promise { const queueCount = await this.operationStateRepository.count(); if (queueCount > this.cacheSize) { - // Delete the oldest entries beyond the buffer size + // Delete the oldest entries from the cache const old_states = await this.operationStateRepository.find({ order: { indexedBlockHeight: 'ASC',