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

View file

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

View file

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