From f7a2f9fb3f01130caf3e083dfe6d9796a3f998ed Mon Sep 17 00:00:00 2001 From: NanamiAdmin Date: Wed, 25 Mar 2026 22:35:01 +0800 Subject: [PATCH] refactor(Instances): simplify instance loading logic Replace multiple API calls with a single call and simplify the data mapping. The new implementation directly uses the status field from the list response instead of making separate info requests for each instance. --- src/views/Instances.vue | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/views/Instances.vue b/src/views/Instances.vue index e55dcc5..6961754 100644 --- a/src/views/Instances.vue +++ b/src/views/Instances.vue @@ -203,30 +203,11 @@ export default { const loadInstances = async () => { try { - const listResult = await instanceApi.listInstances(); - const instanceIDs = listResult.data.map(i => String(i.instanceID)); - - const infoResults = await Promise.all(instanceIDs.map(async (instanceID) => { - try { - return await instanceApi.getInstanceInfo(instanceID); - } catch (error) { - console.error(`Failed to get info for instance ${instanceID}:`, error); - return null; - } + const result = await instanceApi.listInstances(); + instances.value = result.data.map(instance => ({ + ...instance, + status: instance.isRunning ? 'running' : 'stopped' })); - - instances.value = listResult.data.map(instance => { - const infoResult = infoResults.find(r => r && String(r.data.instanceID) === String(instance.instanceID)); - if (infoResult) { - return { - ...instance, - status: infoResult.data.isRunning ? 'running' : 'stopped', - serviceName: infoResult.data.serviceName, - pid: infoResult.data.pid - }; - } - return { ...instance, status: 'stopped' }; - }); } catch (error) { showNotification('Load instance list failed', 'error'); }