1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

perf: 浏览器失去焦点停止查询、节省开销 (#1256)

This commit is contained in:
&nbsp 2023-06-05 17:52:53 +08:00 committed by GitHub
parent 75fa498a7c
commit 5e3e580f51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -239,6 +239,7 @@ const isSafety = ref();
const chartOption = ref('network'); const chartOption = ref('network');
let timer: NodeJS.Timer | null = null; let timer: NodeJS.Timer | null = null;
let isInit = ref<boolean>(true); let isInit = ref<boolean>(true);
let isActive = ref(true);
const ioReadBytes = ref<Array<number>>([]); const ioReadBytes = ref<Array<number>>([]);
const ioWriteBytes = ref<Array<number>>([]); const ioWriteBytes = ref<Array<number>>([]);
@ -353,12 +354,14 @@ const onLoadBaseInfo = async (isInit: boolean, range: string) => {
const res = await loadBaseInfo(searchInfo.ioOption, searchInfo.netOption); const res = await loadBaseInfo(searchInfo.ioOption, searchInfo.netOption);
baseInfo.value = res.data; baseInfo.value = res.data;
currentInfo.value = baseInfo.value.currentInfo; currentInfo.value = baseInfo.value.currentInfo;
onLoadCurrentInfo(); await onLoadCurrentInfo();
statuRef.value.acceptParams(currentInfo.value, baseInfo.value); statuRef.value.acceptParams(currentInfo.value, baseInfo.value);
appRef.value.acceptParams(); appRef.value.acceptParams();
if (isInit) { if (isInit) {
timer = setInterval(async () => { timer = setInterval(async () => {
onLoadCurrentInfo(); if (isActive.value) {
await onLoadCurrentInfo();
}
}, 3000); }, 3000);
} }
}; };
@ -511,6 +514,12 @@ const loadSafeStatus = async () => {
}; };
onMounted(() => { onMounted(() => {
window.addEventListener('focus', () => {
isActive.value = true;
});
window.addEventListener('blur', () => {
isActive.value = false;
});
loadSafeStatus(); loadSafeStatus();
loadUpgradeStatus(); loadUpgradeStatus();
onLoadNetworkOptions(); onLoadNetworkOptions();