From f6eb077d82dd805fe384208a5d7c7bf1650da20d Mon Sep 17 00:00:00 2001 From: shaw Date: Thu, 16 Oct 2025 15:35:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96pricing=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=85=B3=E5=81=9C=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E5=AE=9A=E6=97=B6=E5=99=A8=E5=9C=A8=E6=B8=85=E7=90=86?= =?UTF-8?q?=E9=98=B6=E6=AE=B5=E6=AD=A3=E7=A1=AE=E9=87=8A=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/pricingService.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/services/pricingService.js b/src/services/pricingService.js index c3f5ffef..0d0470cb 100644 --- a/src/services/pricingService.js +++ b/src/services/pricingService.js @@ -25,6 +25,7 @@ class PricingService { this.fileWatcher = null // 文件监听器 this.reloadDebounceTimer = null // 防抖定时器 this.hashCheckTimer = null // 哈希轮询定时器 + this.updateTimer = null // 定时更新任务句柄 this.hashSyncInProgress = false // 哈希同步状态 // 硬编码的 1 小时缓存价格(美元/百万 token) @@ -91,7 +92,10 @@ class PricingService { await this.syncWithRemoteHash() // 设置定时更新 - setInterval(() => { + if (this.updateTimer) { + clearInterval(this.updateTimer) + } + this.updateTimer = setInterval(() => { this.checkAndUpdatePricing() }, this.updateInterval) @@ -776,6 +780,11 @@ class PricingService { // 清理资源 cleanup() { + if (this.updateTimer) { + clearInterval(this.updateTimer) + this.updateTimer = null + logger.debug('💰 Pricing update timer cleared') + } if (this.fileWatcher) { this.fileWatcher.close() this.fileWatcher = null @@ -785,6 +794,11 @@ class PricingService { clearTimeout(this.reloadDebounceTimer) this.reloadDebounceTimer = null } + if (this.hashCheckTimer) { + clearInterval(this.hashCheckTimer) + this.hashCheckTimer = null + logger.debug('💰 Hash check timer cleared') + } } }