fix: 修复账号管理页面容量列显示为0的bug

This commit is contained in:
shaw
2026-03-05 09:48:00 +08:00
parent 5b10af85b4
commit 078fefed03
2 changed files with 75 additions and 66 deletions

View File

@@ -240,13 +240,14 @@ func (h *AccountHandler) List(c *gin.Context) {
var windowCosts map[int64]float64
var activeSessions map[int64]int
var rpmCounts map[int64]int
if !lite {
// Get current concurrency counts for all accounts
// 始终获取并发数Redis ZCARD极低开销
if h.concurrencyService != nil {
if cc, ccErr := h.concurrencyService.GetAccountConcurrencyBatch(c.Request.Context(), accountIDs); ccErr == nil && cc != nil {
concurrencyCounts = cc
}
}
// 识别需要查询窗口费用、会话数和 RPM 的账号Anthropic OAuth/SetupToken 且启用了相应功能)
windowCostAccountIDs := make([]int64, 0)
sessionLimitAccountIDs := make([]int64, 0)
@@ -268,7 +269,7 @@ func (h *AccountHandler) List(c *gin.Context) {
}
}
// 获取 RPM 计数(批量查询
// 始终获取 RPM 计数(Redis GET极低开销
if len(rpmAccountIDs) > 0 && h.rpmCache != nil {
rpmCounts, _ = h.rpmCache.GetRPMBatch(c.Request.Context(), rpmAccountIDs)
if rpmCounts == nil {
@@ -276,7 +277,7 @@ func (h *AccountHandler) List(c *gin.Context) {
}
}
// 获取活跃会话数(批量查询,传入各账号的 idleTimeout 配置
// 始终获取活跃会话数(Redis ZCARD低开销
if len(sessionLimitAccountIDs) > 0 && h.sessionLimitCache != nil {
activeSessions, _ = h.sessionLimitCache.GetActiveSessionCountBatch(c.Request.Context(), sessionLimitAccountIDs, sessionIdleTimeouts)
if activeSessions == nil {
@@ -284,8 +285,8 @@ func (h *AccountHandler) List(c *gin.Context) {
}
}
// 获取窗口费用(并行查询
if len(windowCostAccountIDs) > 0 {
// 仅非 lite 模式获取窗口费用PostgreSQL 聚合查询,高开销
if !lite && len(windowCostAccountIDs) > 0 {
windowCosts = make(map[int64]float64)
var mu sync.Mutex
g, gctx := errgroup.WithContext(c.Request.Context())
@@ -311,7 +312,6 @@ func (h *AccountHandler) List(c *gin.Context) {
}
_ = g.Wait()
}
}
// Build response with concurrency info
result := make([]AccountWithConcurrency, len(accounts))

View File

@@ -546,18 +546,27 @@ const {
handlePageSizeChange: baseHandlePageSizeChange
} = useTableLoader<Account, any>({
fetchFn: adminAPI.accounts.list,
initialParams: { platform: '', type: '', status: '', group: '', search: '', lite: '1' }
initialParams: { platform: '', type: '', status: '', group: '', search: '' }
})
const resetAutoRefreshCache = () => {
autoRefreshETag.value = null
}
const isFirstLoad = ref(true)
const load = async () => {
hasPendingListSync.value = false
resetAutoRefreshCache()
pendingTodayStatsRefresh.value = false
if (isFirstLoad.value) {
;(params as any).lite = '1'
}
await baseLoad()
if (isFirstLoad.value) {
isFirstLoad.value = false
delete (params as any).lite
}
await refreshTodayStatsBatch()
}
@@ -689,7 +698,7 @@ const refreshAccountsIncrementally = async () => {
type?: string
status?: string
search?: string
lite?: string
},
{ etag: autoRefreshETag.value }
)