perf: optimize polling, stats cache, and frontend chunk splitting
This commit is contained in:
@@ -405,18 +405,51 @@ async function refreshAll(options = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
const REPORT_POLL_ACTIVE_MS = 5000
|
||||
const REPORT_POLL_HIDDEN_MS = 20000
|
||||
|
||||
let refreshTimer = null
|
||||
|
||||
function isPageHidden() {
|
||||
if (typeof document === 'undefined') return false
|
||||
return document.visibilityState === 'hidden'
|
||||
}
|
||||
|
||||
function currentRefreshDelay() {
|
||||
return isPageHidden() ? REPORT_POLL_HIDDEN_MS : REPORT_POLL_ACTIVE_MS
|
||||
}
|
||||
|
||||
function stopRefreshLoop() {
|
||||
if (!refreshTimer) return
|
||||
clearTimeout(refreshTimer)
|
||||
refreshTimer = null
|
||||
}
|
||||
|
||||
function scheduleRefreshLoop() {
|
||||
stopRefreshLoop()
|
||||
refreshTimer = window.setTimeout(async () => {
|
||||
refreshTimer = null
|
||||
await refreshAll({ showLoading: false }).catch(() => {})
|
||||
scheduleRefreshLoop()
|
||||
}, currentRefreshDelay())
|
||||
}
|
||||
|
||||
function onVisibilityChange() {
|
||||
scheduleRefreshLoop()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
refreshAll({ showLoading: false })
|
||||
refreshTimer = setInterval(() => refreshAll({ showLoading: false }), 5000)
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
scheduleRefreshLoop()
|
||||
})
|
||||
window.addEventListener('visibilitychange', onVisibilityChange)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (refreshTimer) {
|
||||
clearInterval(refreshTimer)
|
||||
refreshTimer = null
|
||||
}
|
||||
stopRefreshLoop()
|
||||
window.removeEventListener('visibilitychange', onVisibilityChange)
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user