perf(frontend): on-demand element plus imports and dedupe stats requests

This commit is contained in:
2026-02-07 17:43:18 +08:00
parent 99ecbcf55e
commit 06fe7f6f68
70 changed files with 1168 additions and 175 deletions

View File

@@ -1,3 +1,9 @@
<script setup>
import zhCn from 'element-plus/es/locale/lang/zh-cn'
</script>
<template>
<RouterView />
<el-config-provider :locale="zhCn">
<RouterView />
</el-config-provider>
</template>

View File

@@ -1,13 +1,23 @@
import { api } from './client'
let _feedbackStatsInflight = null
export async function fetchFeedbacks(status = '') {
const { data } = await api.get('/feedbacks', { params: status ? { status } : {} })
return data
}
export async function fetchFeedbackStats() {
const { data } = await api.get('/feedbacks', { params: { limit: 1, offset: 0 } })
return data?.stats
if (_feedbackStatsInflight) return _feedbackStatsInflight
_feedbackStatsInflight = api
.get('/feedbacks', { params: { limit: 1, offset: 0 } })
.then(({ data }) => data?.stats)
.finally(() => {
_feedbackStatsInflight = null
})
return _feedbackStatsInflight
}
export async function replyFeedback(feedbackId, reply) {

View File

@@ -1,7 +1,42 @@
import { api } from './client'
export async function fetchSystemStats() {
const { data } = await api.get('/stats')
return data
const _statsCache = {
value: null,
expiresAt: 0,
inflight: null,
}
const SYSTEM_STATS_TTL_MS = 2000
export async function fetchSystemStats(options = {}) {
const force = Boolean(options?.force)
const now = Date.now()
if (!force && _statsCache.value && now < _statsCache.expiresAt) {
return _statsCache.value
}
if (!force && _statsCache.inflight) {
return _statsCache.inflight
}
const request = api
.get('/stats')
.then(({ data }) => {
_statsCache.value = data
_statsCache.expiresAt = Date.now() + SYSTEM_STATS_TTL_MS
return data
})
.finally(() => {
_statsCache.inflight = null
})
_statsCache.inflight = request
return request
}
export function clearSystemStatsCache() {
_statsCache.value = null
_statsCache.expiresAt = 0
_statsCache.inflight = null
}

View File

@@ -3,10 +3,7 @@ import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import 'element-plus/dist/index.css'
import './style.css'
createApp(App).use(router).use(ElementPlus, { locale: zhCn }).mount('#app')
createApp(App).use(router).mount('#app')