perf(frontend): add api cache layer and reduce report polling pressure

This commit is contained in:
2026-02-07 18:36:55 +08:00
parent c285d1e348
commit 4874aa37f6
38 changed files with 205 additions and 131 deletions

View File

@@ -550,9 +550,17 @@ const mobileModules = computed(() => [
},
])
const REPORT_SYNC_STATS_EVERY = 3
let reportRefreshTick = 0
async function refreshAll(options = {}) {
const showLoading = options.showLoading ?? true
if (refreshing.value) return
const forceStatsSync = Boolean(options.forceStatsSync)
const shouldSyncStats = forceStatsSync || reportRefreshTick % REPORT_SYNC_STATS_EVERY === 0
reportRefreshTick += 1
refreshing.value = true
if (showLoading) {
loading.value = true
@@ -593,7 +601,9 @@ async function refreshAll(options = {}) {
if (slowSqlResult.status === 'fulfilled') slowSqlMetrics.value = slowSqlResult.value
if (configResult.status === 'fulfilled') systemConfig.value = configResult.value
await refreshStats?.()
if (shouldSyncStats) {
await refreshStats?.({ force: forceStatsSync })
}
recordUpdatedAt()
} finally {
refreshing.value = false
@@ -637,7 +647,7 @@ function onVisibilityChange() {
}
onMounted(() => {
refreshAll({ showLoading: false })
refreshAll({ showLoading: false, forceStatsSync: true })
.catch(() => {})
.finally(() => {
scheduleRefreshLoop()