optimize fetch time
This commit is contained in:
@@ -46,7 +46,8 @@ export const useSoftwareStore = defineStore('software', {
|
||||
isInitialized: false,
|
||||
initStatus: '正在检查系统环境...',
|
||||
lastFetched: 0,
|
||||
refreshTimer: null as any
|
||||
refreshTimer: null as any,
|
||||
batchQueue: [] as string[]
|
||||
}),
|
||||
getters: {
|
||||
mergedEssentials: (state) => {
|
||||
@@ -246,23 +247,28 @@ export const useSoftwareStore = defineStore('software', {
|
||||
}
|
||||
},
|
||||
|
||||
// 引入防抖刷新:在批量安装期间,仅在最后一次成功后的 5 秒执行全量扫描
|
||||
// 注册批量任务
|
||||
startBatch(ids: string[]) {
|
||||
this.batchQueue = [...ids];
|
||||
},
|
||||
|
||||
// 引入防抖刷新:仅在批量任务全部处理完后的 2 秒执行全量扫描
|
||||
scheduleDataRefresh() {
|
||||
if (this.refreshTimer) clearTimeout(this.refreshTimer);
|
||||
|
||||
this.refreshTimer = setTimeout(async () => {
|
||||
// 执行全量刷新
|
||||
await this.fetchAllData();
|
||||
|
||||
// 刷新完成后清理所有已成功的任务状态,让卡片恢复正常显示
|
||||
// 刷新完成后清理所有已终结(成功或失败)的任务状态快照
|
||||
Object.keys(this.activeTasks).forEach(id => {
|
||||
if (this.activeTasks[id].status === 'success') {
|
||||
const status = this.activeTasks[id].status;
|
||||
if (status === 'success' || status === 'error') {
|
||||
delete this.activeTasks[id];
|
||||
}
|
||||
});
|
||||
|
||||
this.refreshTimer = null;
|
||||
}, 5000);
|
||||
}, 2000);
|
||||
},
|
||||
|
||||
findSoftware(id: string) {
|
||||
@@ -279,15 +285,25 @@ export const useSoftwareStore = defineStore('software', {
|
||||
const task = this.activeTasks[id];
|
||||
this.activeTasks[id] = { status, progress, targetVersion: task?.targetVersion };
|
||||
|
||||
// 当任务达到终态(成功或失败)时
|
||||
if (status === 'success' || status === 'error') {
|
||||
if (status === 'success') {
|
||||
this.lastFetched = 0;
|
||||
// 立即更新勾选状态,提升响应感
|
||||
this.selectedEssentialIds = this.selectedEssentialIds.filter(i => i !== id);
|
||||
this.selectedUpdateIds = this.selectedUpdateIds.filter(i => i !== id);
|
||||
}
|
||||
|
||||
// 触发防抖刷新
|
||||
// 检查是否属于正在进行的批量任务
|
||||
const index = this.batchQueue.indexOf(id);
|
||||
if (index !== -1) {
|
||||
this.batchQueue.splice(index, 1);
|
||||
// 如果这是批量任务中的最后一个,则触发延迟刷新
|
||||
if (this.batchQueue.length === 0) {
|
||||
this.scheduleDataRefresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
listen('log-event', (event: any) => {
|
||||
|
||||
@@ -78,7 +78,9 @@ const selectableItems = computed(() => {
|
||||
});
|
||||
|
||||
const installSelected = () => {
|
||||
store.selectedEssentialIds.forEach(id => {
|
||||
const ids = [...store.selectedEssentialIds];
|
||||
store.startBatch(ids);
|
||||
ids.forEach(id => {
|
||||
const item = store.mergedEssentials.find(s => s.id === id);
|
||||
if (item) {
|
||||
store.install(id, item.targetVersion);
|
||||
|
||||
@@ -78,7 +78,9 @@ import { onMounted } from 'vue';
|
||||
const store = useSoftwareStore();
|
||||
|
||||
const updateSelected = () => {
|
||||
store.selectedUpdateIds.forEach(id => {
|
||||
const ids = [...store.selectedUpdateIds];
|
||||
store.startBatch(ids);
|
||||
ids.forEach(id => {
|
||||
const item = store.sortedUpdates.find(s => s.id === id);
|
||||
if (item && item.targetVersion) {
|
||||
store.install(id, item.targetVersion);
|
||||
|
||||
Reference in New Issue
Block a user