mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
fix: 修复 ESLint 错误和代码格式问题
- 修复 cacheMonitor.js 中未使用的变量 'name' - 移除未使用的变量以通过 ESLint 检查 - 确保 npm run dev 能正常运行 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -192,8 +192,8 @@ class RedisClient {
|
|||||||
cacheCreateTokens = 0,
|
cacheCreateTokens = 0,
|
||||||
cacheReadTokens = 0,
|
cacheReadTokens = 0,
|
||||||
model = 'unknown',
|
model = 'unknown',
|
||||||
ephemeral5mTokens = 0, // 新增:5分钟缓存 tokens
|
ephemeral5mTokens = 0, // 新增:5分钟缓存 tokens
|
||||||
ephemeral1hTokens = 0 // 新增:1小时缓存 tokens
|
ephemeral1hTokens = 0 // 新增:1小时缓存 tokens
|
||||||
) {
|
) {
|
||||||
const key = `usage:${keyId}`
|
const key = `usage:${keyId}`
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
|
|||||||
@@ -484,12 +484,12 @@ class ApiKeyService {
|
|||||||
// 提取详细的缓存创建数据
|
// 提取详细的缓存创建数据
|
||||||
let ephemeral5mTokens = 0
|
let ephemeral5mTokens = 0
|
||||||
let ephemeral1hTokens = 0
|
let ephemeral1hTokens = 0
|
||||||
|
|
||||||
if (usageObject.cache_creation && typeof usageObject.cache_creation === 'object') {
|
if (usageObject.cache_creation && typeof usageObject.cache_creation === 'object') {
|
||||||
ephemeral5mTokens = usageObject.cache_creation.ephemeral_5m_input_tokens || 0
|
ephemeral5mTokens = usageObject.cache_creation.ephemeral_5m_input_tokens || 0
|
||||||
ephemeral1hTokens = usageObject.cache_creation.ephemeral_1h_input_tokens || 0
|
ephemeral1hTokens = usageObject.cache_creation.ephemeral_1h_input_tokens || 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// 记录API Key级别的使用统计 - 这个必须执行
|
// 记录API Key级别的使用统计 - 这个必须执行
|
||||||
await redis.incrementTokenUsage(
|
await redis.incrementTokenUsage(
|
||||||
keyId,
|
keyId,
|
||||||
@@ -499,8 +499,8 @@ class ApiKeyService {
|
|||||||
cacheCreateTokens,
|
cacheCreateTokens,
|
||||||
cacheReadTokens,
|
cacheReadTokens,
|
||||||
model,
|
model,
|
||||||
ephemeral5mTokens, // 传递5分钟缓存 tokens
|
ephemeral5mTokens, // 传递5分钟缓存 tokens
|
||||||
ephemeral1hTokens // 传递1小时缓存 tokens
|
ephemeral1hTokens // 传递1小时缓存 tokens
|
||||||
)
|
)
|
||||||
|
|
||||||
// 记录费用统计
|
// 记录费用统计
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class CacheMonitor {
|
|||||||
|
|
||||||
const totalRequests = stats.totalHits + stats.totalMisses
|
const totalRequests = stats.totalHits + stats.totalMisses
|
||||||
stats.averageHitRate =
|
stats.averageHitRate =
|
||||||
totalRequests > 0 ? ((stats.totalHits / totalRequests) * 100).toFixed(2) + '%' : '0%'
|
totalRequests > 0 ? `${((stats.totalHits / totalRequests) * 100).toFixed(2)}%` : '0%'
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ class CacheMonitor {
|
|||||||
|
|
||||||
for (const [name, monitor] of this.monitors) {
|
for (const [name, monitor] of this.monitors) {
|
||||||
try {
|
try {
|
||||||
const cache = monitor.cache
|
const { cache } = monitor
|
||||||
const beforeSize = cache.cache.size
|
const beforeSize = cache.cache.size
|
||||||
|
|
||||||
// 执行常规清理
|
// 执行常规清理
|
||||||
@@ -251,8 +251,8 @@ class CacheMonitor {
|
|||||||
estimateMemoryUsage() {
|
estimateMemoryUsage() {
|
||||||
let totalBytes = 0
|
let totalBytes = 0
|
||||||
|
|
||||||
for (const [name, monitor] of this.monitors) {
|
for (const [, monitor] of this.monitors) {
|
||||||
const cache = monitor.cache.cache
|
const { cache } = monitor.cache
|
||||||
for (const [key, item] of cache) {
|
for (const [key, item] of cache) {
|
||||||
// 粗略估算:key 长度 + value 序列化长度
|
// 粗略估算:key 长度 + value 序列化长度
|
||||||
totalBytes += key.length * 2 // UTF-16
|
totalBytes += key.length * 2 // UTF-16
|
||||||
@@ -275,7 +275,7 @@ class CacheMonitor {
|
|||||||
logger.error('🚨 EMERGENCY CLEANUP INITIATED')
|
logger.error('🚨 EMERGENCY CLEANUP INITIATED')
|
||||||
|
|
||||||
for (const [name, monitor] of this.monitors) {
|
for (const [name, monitor] of this.monitors) {
|
||||||
const cache = monitor.cache
|
const { cache } = monitor
|
||||||
const beforeSize = cache.cache.size
|
const beforeSize = cache.cache.size
|
||||||
|
|
||||||
// 清理一半的缓存项(LRU 会保留最近使用的)
|
// 清理一半的缓存项(LRU 会保留最近使用的)
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class LRUCache {
|
|||||||
* 清空缓存
|
* 清空缓存
|
||||||
*/
|
*/
|
||||||
clear() {
|
clear() {
|
||||||
const size = this.cache.size
|
const { size } = this.cache
|
||||||
this.cache.clear()
|
this.cache.clear()
|
||||||
this.hits = 0
|
this.hits = 0
|
||||||
this.misses = 0
|
this.misses = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user