perf(stability): add request metrics and resilient API retries
This commit is contained in:
@@ -34,7 +34,11 @@ async function refreshStats() {
|
||||
|
||||
const loadingBadges = ref(false)
|
||||
const pendingFeedbackCount = ref(0)
|
||||
let badgeTimer
|
||||
|
||||
const BADGE_POLL_ACTIVE_MS = 60_000
|
||||
const BADGE_POLL_HIDDEN_MS = 180_000
|
||||
|
||||
let badgeTimer = null
|
||||
|
||||
async function refreshNavBadges(partial = null) {
|
||||
if (partial && typeof partial === 'object') {
|
||||
@@ -55,6 +59,34 @@ async function refreshNavBadges(partial = null) {
|
||||
}
|
||||
}
|
||||
|
||||
function isPageHidden() {
|
||||
if (typeof document === 'undefined') return false
|
||||
return document.visibilityState === 'hidden'
|
||||
}
|
||||
|
||||
function currentBadgePollDelay() {
|
||||
return isPageHidden() ? BADGE_POLL_HIDDEN_MS : BADGE_POLL_ACTIVE_MS
|
||||
}
|
||||
|
||||
function stopBadgePolling() {
|
||||
if (!badgeTimer) return
|
||||
window.clearTimeout(badgeTimer)
|
||||
badgeTimer = null
|
||||
}
|
||||
|
||||
function scheduleBadgePolling() {
|
||||
stopBadgePolling()
|
||||
badgeTimer = window.setTimeout(async () => {
|
||||
badgeTimer = null
|
||||
await refreshNavBadges().catch(() => {})
|
||||
scheduleBadgePolling()
|
||||
}, currentBadgePollDelay())
|
||||
}
|
||||
|
||||
function onVisibilityChange() {
|
||||
scheduleBadgePolling()
|
||||
}
|
||||
|
||||
provide('refreshStats', refreshStats)
|
||||
provide('adminStats', stats)
|
||||
provide('refreshNavBadges', refreshNavBadges)
|
||||
@@ -75,12 +107,14 @@ onMounted(async () => {
|
||||
|
||||
await refreshStats()
|
||||
await refreshNavBadges()
|
||||
badgeTimer = window.setInterval(refreshNavBadges, 60_000)
|
||||
scheduleBadgePolling()
|
||||
window.addEventListener('visibilitychange', onVisibilityChange)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
mediaQuery?.removeEventListener?.('change', syncIsMobile)
|
||||
window.clearInterval(badgeTimer)
|
||||
stopBadgePolling()
|
||||
window.removeEventListener('visibilitychange', onVisibilityChange)
|
||||
})
|
||||
|
||||
const menuItems = [
|
||||
|
||||
Reference in New Issue
Block a user