optimize fetch logic
This commit is contained in:
@@ -118,10 +118,21 @@ export const useSoftwareStore = defineStore('software', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async fetchEssentials() {
|
async fetchEssentials() {
|
||||||
const res = await invoke('get_essentials') as any;
|
let repo = await invoke('get_essentials') as any;
|
||||||
if (res) {
|
|
||||||
this.essentials = res.essentials;
|
// 如果本地没有文件,则尝试联网获取一次
|
||||||
this.essentialsVersion = res.version;
|
if (!repo) {
|
||||||
|
try {
|
||||||
|
await invoke('sync_essentials');
|
||||||
|
repo = await invoke('get_essentials') as any;
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Initial sync failed:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (repo) {
|
||||||
|
this.essentials = repo.essentials;
|
||||||
|
this.essentialsVersion = repo.version;
|
||||||
} else {
|
} else {
|
||||||
this.essentials = [];
|
this.essentials = [];
|
||||||
this.essentialsVersion = '';
|
this.essentialsVersion = '';
|
||||||
@@ -161,23 +172,15 @@ export const useSoftwareStore = defineStore('software', {
|
|||||||
async fetchAllData() {
|
async fetchAllData() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
try {
|
try {
|
||||||
// 在获取全量数据之前,先同步云端清单
|
// 先确保加载了必备清单(内部处理本地缺失逻辑)
|
||||||
await invoke('sync_essentials').catch(() => {});
|
await this.fetchEssentials();
|
||||||
|
|
||||||
const [repo, all, updates] = await Promise.all([
|
// 然后同步本地软件安装/更新状态,不再强制联网下载 JSON
|
||||||
invoke('get_essentials') as Promise<any>,
|
const [all, updates] = await Promise.all([
|
||||||
invoke('get_all_software'),
|
invoke('get_all_software'),
|
||||||
invoke('get_updates')
|
invoke('get_updates')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (repo) {
|
|
||||||
this.essentials = repo.essentials;
|
|
||||||
this.essentialsVersion = repo.version;
|
|
||||||
} else {
|
|
||||||
this.essentials = [];
|
|
||||||
this.essentialsVersion = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
this.allSoftware = all as any[];
|
this.allSoftware = all as any[];
|
||||||
this.updates = updates as any[];
|
this.updates = updates as any[];
|
||||||
this.lastFetched = Date.now();
|
this.lastFetched = Date.now();
|
||||||
|
|||||||
Reference in New Issue
Block a user