mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
fix: user stats again x4
This commit is contained in:
@@ -500,16 +500,6 @@ class ApiKeyService {
|
||||
const dailyCost = (await redis.getDailyCost(key.id)) || 0
|
||||
const costStats = await redis.getCostStats(key.id)
|
||||
|
||||
logger.debug(`🔍 getUserApiKeys: Key ${key.id} (${key.name}) usage:`, {
|
||||
keyId: key.id,
|
||||
keyName: key.name,
|
||||
userId: key.userId,
|
||||
rawUsage: usage,
|
||||
dailyCost,
|
||||
costStats,
|
||||
lastUsedAt: key.lastUsedAt
|
||||
})
|
||||
|
||||
userKeysWithUsage.push({
|
||||
id: key.id,
|
||||
name: key.name,
|
||||
@@ -673,11 +663,12 @@ class ApiKeyService {
|
||||
// 汇总所有API Key的统计数据
|
||||
for (const keyId of keyIds) {
|
||||
const keyStats = await redis.getUsageStats(keyId)
|
||||
if (keyStats) {
|
||||
stats.totalRequests += keyStats.requests || 0
|
||||
stats.totalInputTokens += keyStats.inputTokens || 0
|
||||
stats.totalOutputTokens += keyStats.outputTokens || 0
|
||||
stats.totalCost += keyStats.totalCost || 0
|
||||
const costStats = await redis.getCostStats(keyId)
|
||||
if (keyStats && keyStats.total) {
|
||||
stats.totalRequests += keyStats.total.requests || 0
|
||||
stats.totalInputTokens += keyStats.total.inputTokens || 0
|
||||
stats.totalOutputTokens += keyStats.total.outputTokens || 0
|
||||
stats.totalCost += costStats?.total || 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,10 +150,6 @@ class UserService {
|
||||
}
|
||||
|
||||
for (const apiKey of userApiKeys) {
|
||||
logger.debug(`🔍 Processing API key ${apiKey.id} (${apiKey.name}) for user ${userId}:`, {
|
||||
hasUsage: !!apiKey.usage,
|
||||
usage: apiKey.usage
|
||||
})
|
||||
if (apiKey.usage && apiKey.usage.total) {
|
||||
totalUsage.requests += apiKey.usage.total.requests || 0
|
||||
totalUsage.inputTokens += apiKey.usage.total.inputTokens || 0
|
||||
|
||||
Reference in New Issue
Block a user