Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions frontend/src/views/home/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ const isSafety = ref();
const chartOption = ref('network');
let timer: NodeJS.Timer | null = null;
let isInit = ref<boolean>(true);
let isActive = ref(true);

const ioReadBytes = ref<Array<number>>([]);
const ioWriteBytes = ref<Array<number>>([]);
Expand Down Expand Up @@ -353,12 +354,14 @@ const onLoadBaseInfo = async (isInit: boolean, range: string) => {
const res = await loadBaseInfo(searchInfo.ioOption, searchInfo.netOption);
baseInfo.value = res.data;
currentInfo.value = baseInfo.value.currentInfo;
onLoadCurrentInfo();
await onLoadCurrentInfo();
statuRef.value.acceptParams(currentInfo.value, baseInfo.value);
appRef.value.acceptParams();
if (isInit) {
timer = setInterval(async () => {
onLoadCurrentInfo();
if (isActive.value) {
await onLoadCurrentInfo();
}
}, 3000);
}
};
Expand Down Expand Up @@ -511,6 +514,12 @@ const loadSafeStatus = async () => {
};

onMounted(() => {
window.addEventListener('focus', () => {
isActive.value = true;
});
window.addEventListener('blur', () => {
isActive.value = false;
});
loadSafeStatus();
loadUpgradeStatus();
onLoadNetworkOptions();
Expand Down