mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
fix: 修复总Token消耗USD计算重复统计问题
- 将usage-costs的all模式改为只使用monthly数据,避免daily、monthly、hourly重复计算 - 更新正则表达式只匹配monthly格式的key - 确保总消耗与模型统计表格的USD计算保持一致 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1190,17 +1190,17 @@ router.get('/usage-costs', authenticateAdmin, async (req, res) => {
|
||||
} else if (period === 'monthly') {
|
||||
pattern = `usage:model:monthly:*:${currentMonth}`;
|
||||
} else {
|
||||
// 全部时间,先尝试从Redis获取所有历史模型统计数据
|
||||
const allModelKeys = await client.keys('usage:model:*:*:*');
|
||||
logger.info(`💰 Total period calculation: found ${allModelKeys.length} model keys`);
|
||||
// 全部时间,先尝试从Redis获取所有历史模型统计数据(只使用monthly数据避免重复计算)
|
||||
const allModelKeys = await client.keys('usage:model:monthly:*:*');
|
||||
logger.info(`💰 Total period calculation: found ${allModelKeys.length} monthly model keys`);
|
||||
|
||||
if (allModelKeys.length > 0) {
|
||||
// 如果有详细的模型统计数据,使用模型级别的计算
|
||||
const modelUsageMap = new Map();
|
||||
|
||||
for (const key of allModelKeys) {
|
||||
// 解析模型名称
|
||||
let modelMatch = key.match(/usage:model:(?:daily|monthly|hourly):(.+):(\d{4}-\d{2}(?:-\d{2})?(?::\d{2})?)$/);
|
||||
// 解析模型名称(只处理monthly数据)
|
||||
let modelMatch = key.match(/usage:model:monthly:(.+):(\d{4}-\d{2})$/);
|
||||
if (!modelMatch) continue;
|
||||
|
||||
const model = modelMatch[1];
|
||||
|
||||
Reference in New Issue
Block a user