From d2c3eca1f61fd8b9ba48edfd92671266166c3f2a Mon Sep 17 00:00:00 2001 From: boufni95 Date: Wed, 5 Feb 2025 18:12:23 +0000 Subject: [PATCH] path fix --- src/services/storage/stateBundler.ts | 38 ++++++++++++---------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/services/storage/stateBundler.ts b/src/services/storage/stateBundler.ts index a9b1bf08..44799f15 100644 --- a/src/services/storage/stateBundler.ts +++ b/src/services/storage/stateBundler.ts @@ -31,6 +31,7 @@ export type TxPointSettings = { export class StateBundler { tlvStorage: TlvFilesStorage reportLog = getLogger({ component: 'stateBundlerReport' }) + prevValues: Record = {} constructor(settings: StorageSettings) { const bundlerPath = [settings.dataDir, "bundler_events"].filter(s => !!s).join("/") this.tlvStorage = new TlvFilesStorage(bundlerPath) @@ -53,45 +54,38 @@ export class StateBundler { }) return metrics } - /* increment = (key: string, value: number) => { - this.sinceStart[key] = (this.sinceStart[key] || 0) + value - this.sinceLatestReport[key] = (this.sinceLatestReport[key] || 0) + value - this.triggerReportCheck() + AddValue = (appId: string, key: string, v: number) => { + const prevValueKey = `${appId}_${key}` + if (this.prevValues[prevValueKey] === v) { + return } - set = (key: string, value: number) => { - this.sinceStart[key] = value - this.sinceLatestReport[key] = value - this.triggerReportCheck() - } - max = (key: string, value: number) => { - this.sinceStart[key] = Math.max(this.sinceStart[key] || 0, value) - this.sinceLatestReport[key] = Math.max(this.sinceLatestReport[key] || 0, value) - this.triggerReportCheck() - } */ + this.prevValues[prevValueKey] = v + this.tlvStorage.AddTlv(appId, key, this.serializeNow(v)) + } - AddTxPoint = (actionName: TransactionStatePointType, v: number, settings: TxPointSettings, appId = '__root') => { + AddTxPoint = (actionName: TransactionStatePointType, v: number, settings: TxPointSettings, appId = '_root') => { const { used, from } = settings const meta = settings.meta || [] const key = [actionName, from, used, ...meta].join('_') - this.tlvStorage.AddTlv(appId, key, this.serializeNow(v)) + this.AddValue(appId, key, v) } - AddTxPointFailed = (actionName: TransactionStatePointType, v: number, settings: TxPointSettings, appId = '__root') => { + AddTxPointFailed = (actionName: TransactionStatePointType, v: number, settings: TxPointSettings, appId = '_root') => { const { used, from } = settings const meta = settings.meta || [] const key = [actionName, from, used, ...meta, 'failed'].join('_') - this.tlvStorage.AddTlv(appId, key, this.serializeNow(v)) + this.AddValue(appId, key, v) } - AddBalancePoint = (actionName: BalanceStatePointType, v: number, meta = [], appId = '__root') => { + AddBalancePoint = (actionName: BalanceStatePointType, v: number, meta = [], appId = '_root') => { const key = [actionName, ...meta].join('_') - this.tlvStorage.AddTlv(appId, key, this.serializeNow(v)) + this.AddValue(appId, key, v) } - AddMaxPoint = (actionName: MaxStatePointType, v: number, meta = [], appId = '__root') => { + AddMaxPoint = (actionName: MaxStatePointType, v: number, meta = [], appId = '_root') => { const key = [actionName, ...meta].join('_') - this.tlvStorage.AddTlv(appId, key, this.serializeNow(v)) + this.AddValue(appId, key, v) } serializeNow = (v: number) => {