mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-06 01:17:46 +08:00
fix(usage): calibrate active elapsed clock efficiently
This commit is contained in:
@@ -14,6 +14,7 @@ import { createDefaultStats } from '../types'
|
||||
import { log } from '@/utils/logger'
|
||||
import { getErrorStatus } from '@/types/api-error'
|
||||
import { isUsageProviderVisible, normalizeUsageProviderStats } from '../utils/providerStats'
|
||||
import { useServerClock } from './useServerClock'
|
||||
|
||||
export interface UseUsageDataOptions {
|
||||
isAdminPage: Ref<boolean>
|
||||
@@ -65,6 +66,11 @@ export function useUsageData(options: UseUsageDataOptions) {
|
||||
// 可用的筛选选项(从统计数据获取,而不是从记录中)
|
||||
const availableModels = ref<string[]>([])
|
||||
const availableProviders = ref<string[]>([])
|
||||
const {
|
||||
serverClockOffsetMs,
|
||||
hasServerClockOffset,
|
||||
updateServerClockOffset,
|
||||
} = useServerClock()
|
||||
|
||||
// 增强的模型统计(包含效率分析)
|
||||
const enhancedModelStats = computed<EnhancedModelStatsItem[]>(() => {
|
||||
@@ -213,6 +219,7 @@ export function useUsageData(options: UseUsageDataOptions) {
|
||||
if (requestId !== loadStatsRequestId) {
|
||||
return false
|
||||
}
|
||||
updateServerClockOffset(userData.server_timing)
|
||||
|
||||
stats.value = {
|
||||
total_requests: userData.total_requests || 0,
|
||||
@@ -366,6 +373,7 @@ export function useUsageData(options: UseUsageDataOptions) {
|
||||
if (requestId !== loadRecordsRequestId) {
|
||||
return
|
||||
}
|
||||
updateServerClockOffset(response.server_timing)
|
||||
const nextRecords = (response.records || []) as UsageRecord[]
|
||||
currentRecords.value = mergeRecordStatus(currentRecords.value, nextRecords)
|
||||
totalRecords.value = response.total || 0
|
||||
@@ -375,6 +383,7 @@ export function useUsageData(options: UseUsageDataOptions) {
|
||||
if (requestId !== loadRecordsRequestId) {
|
||||
return
|
||||
}
|
||||
updateServerClockOffset(userData.server_timing)
|
||||
const nextRecords = (userData.records || []) as UsageRecord[]
|
||||
currentRecords.value = mergeRecordStatus(currentRecords.value, nextRecords)
|
||||
totalRecords.value = userData.pagination?.total || currentRecords.value.length
|
||||
@@ -557,6 +566,8 @@ export function useUsageData(options: UseUsageDataOptions) {
|
||||
apiFormatStats,
|
||||
currentRecords,
|
||||
totalRecords,
|
||||
serverClockOffsetMs,
|
||||
hasServerClockOffset,
|
||||
|
||||
// 筛选选项
|
||||
availableModels,
|
||||
@@ -568,6 +579,7 @@ export function useUsageData(options: UseUsageDataOptions) {
|
||||
// 方法
|
||||
loadStats,
|
||||
loadRecords,
|
||||
refreshData
|
||||
refreshData,
|
||||
updateServerClockOffset
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user