更新
This commit is contained in:
@@ -39,9 +39,23 @@ const LOGS_PAGE_SIZE = 20
|
||||
const hasMoreLogs = ref(true)
|
||||
const loadingMore = ref(false)
|
||||
let pollTimer = null
|
||||
let pollStopped = false
|
||||
// 上次日志数据的签名;轮询时数据没变化就跳过赋值,避免无谓的重算与重渲染
|
||||
let lastLogsSignature = ''
|
||||
|
||||
// Use a self-scheduling timeout instead of setInterval. A slow request must
|
||||
// finish before the next poll is scheduled, otherwise overlapping requests can
|
||||
// exhaust the database pool and amplify one slow query into dozens.
|
||||
const scheduleLogPoll = () => {
|
||||
if (pollStopped) return
|
||||
pollTimer = setTimeout(async () => {
|
||||
if (!document.hidden) {
|
||||
await fetchLogs(true)
|
||||
}
|
||||
scheduleLogPoll()
|
||||
}, POLL_INTERVAL_MS)
|
||||
}
|
||||
|
||||
const dedupeMessages = (messages) => {
|
||||
const map = new Map()
|
||||
for (const item of messages) {
|
||||
@@ -593,10 +607,8 @@ onMounted(async () => {
|
||||
}
|
||||
await fetchAccounts()
|
||||
await fetchLogs()
|
||||
pollTimer = setInterval(() => {
|
||||
if (document.hidden) return
|
||||
fetchLogs(true)
|
||||
}, POLL_INTERVAL_MS)
|
||||
pollStopped = false
|
||||
scheduleLogPoll()
|
||||
})
|
||||
|
||||
watch(
|
||||
@@ -613,8 +625,9 @@ watch(
|
||||
)
|
||||
|
||||
onUnmounted(() => {
|
||||
pollStopped = true
|
||||
if (pollTimer) {
|
||||
clearInterval(pollTimer)
|
||||
clearTimeout(pollTimer)
|
||||
pollTimer = null
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user