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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}));
|
||||
|
||||
instances.value = listResult.data.map(instance => {
|
||||
const infoResult = infoResults.find(r => r && String(r.data.instanceID) === String(instance.instanceID));
|
||||
if (infoResult) {
|
||||
return {
|
||||
const result = await instanceApi.listInstances();
|
||||
instances.value = result.data.map(instance => ({
|
||||
...instance,
|
||||
status: infoResult.data.isRunning ? 'running' : 'stopped',
|
||||
serviceName: infoResult.data.serviceName,
|
||||
pid: infoResult.data.pid
|
||||
};
|
||||
}
|
||||
return { ...instance, status: 'stopped' };
|
||||
});
|
||||
status: instance.isRunning ? 'running' : 'stopped'
|
||||
}));
|
||||
} catch (error) {
|
||||
showNotification('Load instance list failed', 'error');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user