fix: Disable caching for recommended apps on the overview page (#11117)

This commit is contained in:
ssongliu 2025-11-28 18:19:27 +08:00 committed by GitHub
parent 2e9305b9b1
commit c0220dbed0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 84 deletions

View file

@ -1,13 +1,7 @@
<template>
<div>
<CardWithHeader
:header="$t('app.app')"
class="card-interval"
v-loading="loading"
@mouseenter="refreshLauncherOnHover"
>
<CardWithHeader :header="$t('app.app')" class="card-interval" v-loading="loading">
<template #header-r>
<el-button class="h-button-setting" link icon="Refresh" @click="refreshLauncher" />
<el-popover placement="left" :width="226" trigger="click">
<el-input size="small" v-model="filter" clearable @input="loadOption()" />
<el-table :show-header="false" :data="options" max-height="150px">
@ -191,41 +185,25 @@ import { changeLauncherStatus, loadAppLauncher, loadAppLauncherOption } from '@/
import i18n from '@/lang';
import { GlobalStore } from '@/store';
import { MsgSuccess } from '@/utils/message';
import { ref, computed } from 'vue';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { jumpToPath } from '@/utils/util';
import { jumpToInstall } from '@/utils/app';
import { routerToFileWithPath, routerToNameWithQuery } from '@/utils/router';
import { clearDashboardCacheByPrefix, getDashboardCache, setDashboardCache } from '@/utils/dashboardCache';
const router = useRouter();
const globalStore = GlobalStore();
const DASHBOARD_CACHE_TTL = {
launcherOption: 5 * 60 * 1000,
launcher: 10 * 60 * 1000,
systemIP: 10 * 60 * 1000,
};
const clearLauncherCache = () => {
clearDashboardCacheByPrefix(['appLauncherOption-', 'appLauncher', 'systemIP']);
};
let loading = ref(false);
let apps = ref([]);
const options = ref([]);
const filter = ref();
const launcherFromCache = ref(false);
const launcherOptionFromCache = ref(false);
const systemIPFromCache = ref(false);
const hasRefreshedLauncherOnHover = ref(false);
const mobile = computed(() => {
return globalStore.isMobile();
});
const defaultLink = ref('');
const acceptParams = (): void => {
hasRefreshedLauncherOnHover.value = false;
search();
loadOption();
getConfig();
@ -237,31 +215,17 @@ const goInstall = (key: string, type: string) => {
}
};
const search = async (force?: boolean) => {
const search = async () => {
loading.value = true;
const cache = force ? null : getDashboardCache('appLauncher');
if (cache !== null) {
apps.value = cache;
launcherFromCache.value = true;
for (const item of apps.value) {
if (item.detail && item.detail.length !== 0) {
item.currentRow = item.detail[0];
}
}
loading.value = false;
return;
}
await loadAppLauncher()
.then((res) => {
loading.value = false;
apps.value = res.data;
launcherFromCache.value = false;
for (const item of apps.value) {
if (item.detail && item.detail.length !== 0) {
item.currentRow = item.detail[0];
}
}
setDashboardCache('appLauncher', apps.value, DASHBOARD_CACHE_TTL.launcher);
})
.finally(() => {
loading.value = false;
@ -274,9 +238,7 @@ const onChangeStatus = async (row: any) => {
.then(() => {
loading.value = false;
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
clearLauncherCache();
search();
loadOption();
})
.catch(() => {
loading.value = false;
@ -287,18 +249,12 @@ const toLink = (link: string) => {
window.open(link, '_blank');
};
const getConfig = async (force?: boolean) => {
const getConfig = async () => {
try {
const cache = force ? null : getDashboardCache('systemIP');
if (cache !== null) {
defaultLink.value = cache;
systemIPFromCache.value = true;
return;
}
const res = await getAgentSettingByKey('SystemIP');
defaultLink.value = res.data || '';
systemIPFromCache.value = false;
setDashboardCache('systemIP', defaultLink.value, DASHBOARD_CACHE_TTL.systemIP);
if (res.data != '') {
defaultLink.value = res.data;
}
} catch (error) {}
};
@ -330,33 +286,9 @@ const onOperate = async (operation: string, row: any) => {
});
};
const loadOption = async (force?: boolean) => {
const cacheKey = `appLauncherOption-${filter.value || ''}`;
const cache = force ? null : getDashboardCache(cacheKey);
if (cache !== null) {
options.value = cache;
launcherOptionFromCache.value = true;
return;
}
const loadOption = async () => {
const res = await loadAppLauncherOption(filter.value || '');
options.value = res.data || [];
launcherOptionFromCache.value = false;
setDashboardCache(cacheKey, options.value, DASHBOARD_CACHE_TTL.launcherOption);
};
const refreshLauncher = async () => {
clearLauncherCache();
hasRefreshedLauncherOnHover.value = false;
await Promise.allSettled([loadOption(true), search(true), getConfig(true)]);
};
const refreshLauncherOnHover = async () => {
if (hasRefreshedLauncherOnHover.value) return;
if (!launcherFromCache.value && !launcherOptionFromCache.value && !systemIPFromCache.value) return;
hasRefreshedLauncherOnHover.value = true;
await loadOption(true);
await search(true);
await getConfig(true);
};
defineExpose({

View file

@ -337,6 +337,7 @@ import { storeToRefs } from 'pinia';
import { routerToFileWithPath, routerToPath } from '@/utils/router';
import { getWelcomePage } from '@/api/modules/auth';
import { clearDashboardCache, getDashboardCache, setDashboardCache } from '@/utils/dashboardCache';
import { MsgSuccess } from '@/utils/message';
const router = useRouter();
const globalStore = GlobalStore();
@ -480,9 +481,6 @@ const applyDefaultNetOption = () => {
const defaultNet = globalStore.defaultNetwork || netOptions.value[0];
if (defaultNet && searchInfo.netOption !== defaultNet) {
searchInfo.netOption = defaultNet;
if (!isStatusInit.value) {
onLoadBaseInfo(false, 'network');
}
}
};
@ -511,9 +509,6 @@ const applyDefaultIOOption = () => {
const defaultIO = globalStore.defaultIO || ioOptions.value[0];
if (defaultIO && searchInfo.ioOption !== defaultIO) {
searchInfo.ioOption = defaultIO;
if (!isStatusInit.value) {
onLoadBaseInfo(false, 'io');
}
}
};
@ -585,8 +580,8 @@ const toggleSensitiveInfo = () => {
const refreshDashboard = async () => {
clearDashboardCache();
hasRefreshedOptionsOnHover.value = false;
await onLoadBaseInfo(false, 'all');
await Promise.allSettled([onLoadSimpleNode(), onLoadNetworkOptions(true), onLoadIOOptions(true), loadSafeStatus()]);
await Promise.allSettled([onLoadNetworkOptions(true), onLoadIOOptions(true), loadSafeStatus()]);
MsgSuccess(i18n.global.t('commons.msg.refreshSuccess'));
};
const jumpPanel = (row: any) => {

View file

@ -31,6 +31,7 @@ import { updateSetting } from '@/api/modules/setting';
import { GlobalStore } from '@/store';
import { getRandomStr } from '@/utils/util';
import { FormInstance } from 'element-plus';
import { clearDashboardCacheByPrefix } from '@/utils/dashboardCache';
const globalStore = GlobalStore();
const emit = defineEmits<{ (e: 'search'): void }>();
@ -82,6 +83,7 @@ const submitEntrance = async (formEl: FormInstance | undefined) => {
loading.value = true;
await updateSetting(param)
.then(() => {
clearDashboardCacheByPrefix(['safeStatus']);
globalStore.setShowEntranceWarn(show.value);
globalStore.entrance = form.securityEntrance;
loading.value = false;