mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 01:40:21 +08:00
feat(usage): 管理员用量统计支持筛选刷新与失败保留旧数据
- 用量统计/聚合接口新增 skipCache 选项与 120s 超时,便于强制绕过缓存 - loadStats 增加 force/preserveOnFailure 选项,背景刷新失败时保留旧数据 - 管理员页面在用户/模型/Provider 筛选变化时强制刷新统计,并将筛选条件传入统计接口 - 手动刷新与自动刷新分离,自动刷新不再重载长期热力图相关聚合
This commit is contained in:
@@ -114,4 +114,43 @@ describe('usageApi contract alignment', () => {
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('uses an extended timeout and cache bypass option for admin analytics', async () => {
|
||||
getMock
|
||||
.mockResolvedValueOnce({
|
||||
data: {
|
||||
total_requests: 7,
|
||||
total_tokens: 99,
|
||||
total_cost: 12.34,
|
||||
avg_response_time: 456,
|
||||
},
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
data: [{ provider: 'OpenAI', request_count: 7 }],
|
||||
})
|
||||
|
||||
await usageApi.getUsageStats({ preset: 'last30days' }, { skipCache: true })
|
||||
await usageApi.getUsageByProvider({ preset: 'last30days' }, { skipCache: true })
|
||||
|
||||
expect(cachedRequestMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
expect.stringContaining(':fresh'),
|
||||
expect.any(Function),
|
||||
0
|
||||
)
|
||||
expect(cachedRequestMock).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect.stringContaining(':fresh'),
|
||||
expect.any(Function),
|
||||
0
|
||||
)
|
||||
expect(getMock).toHaveBeenNthCalledWith(1, '/api/admin/usage/stats', {
|
||||
params: { preset: 'last30days' },
|
||||
timeout: 120000,
|
||||
})
|
||||
expect(getMock).toHaveBeenNthCalledWith(2, '/api/admin/usage/aggregation/stats', {
|
||||
params: { group_by: 'provider', preset: 'last30days' },
|
||||
timeout: 120000,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user