From 3d1cd21bc42cca42b77bf4c55bbdbd28bf51ca57 Mon Sep 17 00:00:00 2001 From: shaw Date: Sun, 17 Aug 2025 16:54:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20ESLint=20=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=92=8C=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 cacheMonitor.js 中未使用的变量 'name' - 移除未使用的变量以通过 ESLint 检查 - 确保 npm run dev 能正常运行 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/models/redis.js | 4 ++-- src/services/apiKeyService.js | 8 ++++---- src/utils/cacheMonitor.js | 10 +++++----- src/utils/lruCache.js | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/models/redis.js b/src/models/redis.js index a4a03b10..4d62bda7 100644 --- a/src/models/redis.js +++ b/src/models/redis.js @@ -192,8 +192,8 @@ class RedisClient { cacheCreateTokens = 0, cacheReadTokens = 0, model = 'unknown', - ephemeral5mTokens = 0, // 新增:5分钟缓存 tokens - ephemeral1hTokens = 0 // 新增:1小时缓存 tokens + ephemeral5mTokens = 0, // 新增:5分钟缓存 tokens + ephemeral1hTokens = 0 // 新增:1小时缓存 tokens ) { const key = `usage:${keyId}` const now = new Date() diff --git a/src/services/apiKeyService.js b/src/services/apiKeyService.js index 48759aa8..cf0d9e4a 100644 --- a/src/services/apiKeyService.js +++ b/src/services/apiKeyService.js @@ -484,12 +484,12 @@ class ApiKeyService { // 提取详细的缓存创建数据 let ephemeral5mTokens = 0 let ephemeral1hTokens = 0 - + if (usageObject.cache_creation && typeof usageObject.cache_creation === 'object') { ephemeral5mTokens = usageObject.cache_creation.ephemeral_5m_input_tokens || 0 ephemeral1hTokens = usageObject.cache_creation.ephemeral_1h_input_tokens || 0 } - + // 记录API Key级别的使用统计 - 这个必须执行 await redis.incrementTokenUsage( keyId, @@ -499,8 +499,8 @@ class ApiKeyService { cacheCreateTokens, cacheReadTokens, model, - ephemeral5mTokens, // 传递5分钟缓存 tokens - ephemeral1hTokens // 传递1小时缓存 tokens + ephemeral5mTokens, // 传递5分钟缓存 tokens + ephemeral1hTokens // 传递1小时缓存 tokens ) // 记录费用统计 diff --git a/src/utils/cacheMonitor.js b/src/utils/cacheMonitor.js index ab24bdfc..ece5e478 100644 --- a/src/utils/cacheMonitor.js +++ b/src/utils/cacheMonitor.js @@ -81,7 +81,7 @@ class CacheMonitor { const totalRequests = stats.totalHits + stats.totalMisses stats.averageHitRate = - totalRequests > 0 ? ((stats.totalHits / totalRequests) * 100).toFixed(2) + '%' : '0%' + totalRequests > 0 ? `${((stats.totalHits / totalRequests) * 100).toFixed(2)}%` : '0%' return stats } @@ -95,7 +95,7 @@ class CacheMonitor { for (const [name, monitor] of this.monitors) { try { - const cache = monitor.cache + const { cache } = monitor const beforeSize = cache.cache.size // 执行常规清理 @@ -251,8 +251,8 @@ class CacheMonitor { estimateMemoryUsage() { let totalBytes = 0 - for (const [name, monitor] of this.monitors) { - const cache = monitor.cache.cache + for (const [, monitor] of this.monitors) { + const { cache } = monitor.cache for (const [key, item] of cache) { // 粗略估算:key 长度 + value 序列化长度 totalBytes += key.length * 2 // UTF-16 @@ -275,7 +275,7 @@ class CacheMonitor { logger.error('🚨 EMERGENCY CLEANUP INITIATED') for (const [name, monitor] of this.monitors) { - const cache = monitor.cache + const { cache } = monitor const beforeSize = cache.cache.size // 清理一半的缓存项(LRU 会保留最近使用的) diff --git a/src/utils/lruCache.js b/src/utils/lruCache.js index 0fd5f008..993089ba 100644 --- a/src/utils/lruCache.js +++ b/src/utils/lruCache.js @@ -94,7 +94,7 @@ class LRUCache { * 清空缓存 */ clear() { - const size = this.cache.size + const { size } = this.cache this.cache.clear() this.hits = 0 this.misses = 0