Skip to content

Commit c0220db

Browse files
authored
fix: Disable caching for recommended apps on the overview page (#11117)
1 parent 2e9305b commit c0220db

File tree

3 files changed

+13
-84
lines changed

3 files changed

+13
-84
lines changed

frontend/src/views/home/app/index.vue

Lines changed: 8 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
<template>
22
<div>
3-
<CardWithHeader
4-
:header="$t('app.app')"
5-
class="card-interval"
6-
v-loading="loading"
7-
@mouseenter="refreshLauncherOnHover"
8-
>
3+
<CardWithHeader :header="$t('app.app')" class="card-interval" v-loading="loading">
94
<template #header-r>
10-
<el-button class="h-button-setting" link icon="Refresh" @click="refreshLauncher" />
115
<el-popover placement="left" :width="226" trigger="click">
126
<el-input size="small" v-model="filter" clearable @input="loadOption()" />
137
<el-table :show-header="false" :data="options" max-height="150px">
@@ -191,41 +185,25 @@ import { changeLauncherStatus, loadAppLauncher, loadAppLauncherOption } from '@/
191185
import i18n from '@/lang';
192186
import { GlobalStore } from '@/store';
193187
import { MsgSuccess } from '@/utils/message';
194-
import { ref, computed } from 'vue';
188+
import { ref } from 'vue';
195189
import { useRouter } from 'vue-router';
196190
import { jumpToPath } from '@/utils/util';
197191
import { jumpToInstall } from '@/utils/app';
198192
import { routerToFileWithPath, routerToNameWithQuery } from '@/utils/router';
199-
import { clearDashboardCacheByPrefix, getDashboardCache, setDashboardCache } from '@/utils/dashboardCache';
200193
201194
const router = useRouter();
202195
const globalStore = GlobalStore();
203196
204-
const DASHBOARD_CACHE_TTL = {
205-
launcherOption: 5 * 60 * 1000,
206-
launcher: 10 * 60 * 1000,
207-
systemIP: 10 * 60 * 1000,
208-
};
209-
210-
const clearLauncherCache = () => {
211-
clearDashboardCacheByPrefix(['appLauncherOption-', 'appLauncher', 'systemIP']);
212-
};
213-
214197
let loading = ref(false);
215198
let apps = ref([]);
216199
const options = ref([]);
217200
const filter = ref();
218-
const launcherFromCache = ref(false);
219-
const launcherOptionFromCache = ref(false);
220-
const systemIPFromCache = ref(false);
221-
const hasRefreshedLauncherOnHover = ref(false);
222201
const mobile = computed(() => {
223202
return globalStore.isMobile();
224203
});
225204
const defaultLink = ref('');
226205
227206
const acceptParams = (): void => {
228-
hasRefreshedLauncherOnHover.value = false;
229207
search();
230208
loadOption();
231209
getConfig();
@@ -237,31 +215,17 @@ const goInstall = (key: string, type: string) => {
237215
}
238216
};
239217
240-
const search = async (force?: boolean) => {
218+
const search = async () => {
241219
loading.value = true;
242-
const cache = force ? null : getDashboardCache('appLauncher');
243-
if (cache !== null) {
244-
apps.value = cache;
245-
launcherFromCache.value = true;
246-
for (const item of apps.value) {
247-
if (item.detail && item.detail.length !== 0) {
248-
item.currentRow = item.detail[0];
249-
}
250-
}
251-
loading.value = false;
252-
return;
253-
}
254220
await loadAppLauncher()
255221
.then((res) => {
256222
loading.value = false;
257223
apps.value = res.data;
258-
launcherFromCache.value = false;
259224
for (const item of apps.value) {
260225
if (item.detail && item.detail.length !== 0) {
261226
item.currentRow = item.detail[0];
262227
}
263228
}
264-
setDashboardCache('appLauncher', apps.value, DASHBOARD_CACHE_TTL.launcher);
265229
})
266230
.finally(() => {
267231
loading.value = false;
@@ -274,9 +238,7 @@ const onChangeStatus = async (row: any) => {
274238
.then(() => {
275239
loading.value = false;
276240
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
277-
clearLauncherCache();
278241
search();
279-
loadOption();
280242
})
281243
.catch(() => {
282244
loading.value = false;
@@ -287,18 +249,12 @@ const toLink = (link: string) => {
287249
window.open(link, '_blank');
288250
};
289251
290-
const getConfig = async (force?: boolean) => {
252+
const getConfig = async () => {
291253
try {
292-
const cache = force ? null : getDashboardCache('systemIP');
293-
if (cache !== null) {
294-
defaultLink.value = cache;
295-
systemIPFromCache.value = true;
296-
return;
297-
}
298254
const res = await getAgentSettingByKey('SystemIP');
299-
defaultLink.value = res.data || '';
300-
systemIPFromCache.value = false;
301-
setDashboardCache('systemIP', defaultLink.value, DASHBOARD_CACHE_TTL.systemIP);
255+
if (res.data != '') {
256+
defaultLink.value = res.data;
257+
}
302258
} catch (error) {}
303259
};
304260
@@ -330,33 +286,9 @@ const onOperate = async (operation: string, row: any) => {
330286
});
331287
};
332288
333-
const loadOption = async (force?: boolean) => {
334-
const cacheKey = `appLauncherOption-${filter.value || ''}`;
335-
const cache = force ? null : getDashboardCache(cacheKey);
336-
if (cache !== null) {
337-
options.value = cache;
338-
launcherOptionFromCache.value = true;
339-
return;
340-
}
289+
const loadOption = async () => {
341290
const res = await loadAppLauncherOption(filter.value || '');
342291
options.value = res.data || [];
343-
launcherOptionFromCache.value = false;
344-
setDashboardCache(cacheKey, options.value, DASHBOARD_CACHE_TTL.launcherOption);
345-
};
346-
347-
const refreshLauncher = async () => {
348-
clearLauncherCache();
349-
hasRefreshedLauncherOnHover.value = false;
350-
await Promise.allSettled([loadOption(true), search(true), getConfig(true)]);
351-
};
352-
353-
const refreshLauncherOnHover = async () => {
354-
if (hasRefreshedLauncherOnHover.value) return;
355-
if (!launcherFromCache.value && !launcherOptionFromCache.value && !systemIPFromCache.value) return;
356-
hasRefreshedLauncherOnHover.value = true;
357-
await loadOption(true);
358-
await search(true);
359-
await getConfig(true);
360292
};
361293
362294
defineExpose({

frontend/src/views/home/index.vue

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ import { storeToRefs } from 'pinia';
337337
import { routerToFileWithPath, routerToPath } from '@/utils/router';
338338
import { getWelcomePage } from '@/api/modules/auth';
339339
import { clearDashboardCache, getDashboardCache, setDashboardCache } from '@/utils/dashboardCache';
340+
import { MsgSuccess } from '@/utils/message';
340341
const router = useRouter();
341342
const globalStore = GlobalStore();
342343
@@ -480,9 +481,6 @@ const applyDefaultNetOption = () => {
480481
const defaultNet = globalStore.defaultNetwork || netOptions.value[0];
481482
if (defaultNet && searchInfo.netOption !== defaultNet) {
482483
searchInfo.netOption = defaultNet;
483-
if (!isStatusInit.value) {
484-
onLoadBaseInfo(false, 'network');
485-
}
486484
}
487485
};
488486
@@ -511,9 +509,6 @@ const applyDefaultIOOption = () => {
511509
const defaultIO = globalStore.defaultIO || ioOptions.value[0];
512510
if (defaultIO && searchInfo.ioOption !== defaultIO) {
513511
searchInfo.ioOption = defaultIO;
514-
if (!isStatusInit.value) {
515-
onLoadBaseInfo(false, 'io');
516-
}
517512
}
518513
};
519514
@@ -585,8 +580,8 @@ const toggleSensitiveInfo = () => {
585580
const refreshDashboard = async () => {
586581
clearDashboardCache();
587582
hasRefreshedOptionsOnHover.value = false;
588-
await onLoadBaseInfo(false, 'all');
589-
await Promise.allSettled([onLoadSimpleNode(), onLoadNetworkOptions(true), onLoadIOOptions(true), loadSafeStatus()]);
583+
await Promise.allSettled([onLoadNetworkOptions(true), onLoadIOOptions(true), loadSafeStatus()]);
584+
MsgSuccess(i18n.global.t('commons.msg.refreshSuccess'));
590585
};
591586
592587
const jumpPanel = (row: any) => {

frontend/src/views/setting/safe/entrance/index.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { updateSetting } from '@/api/modules/setting';
3131
import { GlobalStore } from '@/store';
3232
import { getRandomStr } from '@/utils/util';
3333
import { FormInstance } from 'element-plus';
34+
import { clearDashboardCacheByPrefix } from '@/utils/dashboardCache';
3435
const globalStore = GlobalStore();
3536
3637
const emit = defineEmits<{ (e: 'search'): void }>();
@@ -82,6 +83,7 @@ const submitEntrance = async (formEl: FormInstance | undefined) => {
8283
loading.value = true;
8384
await updateSetting(param)
8485
.then(() => {
86+
clearDashboardCacheByPrefix(['safeStatus']);
8587
globalStore.setShowEntranceWarn(show.value);
8688
globalStore.entrance = form.securityEntrance;
8789
loading.value = false;

0 commit comments

Comments
 (0)