mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 13:07:08 +00:00
Try to improve responsiveness when refreshing project list
This commit is contained in:
@@ -5,6 +5,17 @@ import { duration_to_ms, ms_to_duration, normalise_duration, add_durations } fro
|
|||||||
*/
|
*/
|
||||||
async function refreshProjects ({commit, dispatch, state, rootState}) {
|
async function refreshProjects ({commit, dispatch, state, rootState}) {
|
||||||
|
|
||||||
|
async function getSummary (project) {
|
||||||
|
const url = `/project/${project.pid}/summary`;
|
||||||
|
const init = {};
|
||||||
|
const summary = await dispatch('api', [url, init, null, {silent:true}]);
|
||||||
|
if (summary) {
|
||||||
|
return {...project, ...summary};
|
||||||
|
} else {
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (state.loading) {
|
if (state.loading) {
|
||||||
commit('abortProjectsLoading');
|
commit('abortProjectsLoading');
|
||||||
}
|
}
|
||||||
@@ -20,23 +31,22 @@ async function refreshProjects ({commit, dispatch, state, rootState}) {
|
|||||||
const res = await dispatch('api', [url, init, null, {silent:true}]);
|
const res = await dispatch('api', [url, init, null, {silent:true}]);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
for (let index in res) {
|
|
||||||
const project = res[index];
|
|
||||||
|
|
||||||
if (!project.pid) {
|
let projects;
|
||||||
console.warn("Project has no Project ID!");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = `/project/${project.pid}/summary`;
|
if (res.some( project => project.pid == null )) {
|
||||||
const init = {};
|
console.warn("At least one project found with no PID!");
|
||||||
const summary = await dispatch('api', [url, init, null, {silent:true}]);
|
projects = res.filter( project => project.pid != null );
|
||||||
if (summary) {
|
} else {
|
||||||
res[index] = {...project, ...summary};
|
projects = res;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
commit('setProjects', res);
|
|
||||||
|
commit('setProjects', projects); // First without summaries
|
||||||
commit('setProjectsTimestamp', tstamp);
|
commit('setProjectsTimestamp', tstamp);
|
||||||
|
|
||||||
|
projects = await Promise.all(projects.map( getSummary ));
|
||||||
|
|
||||||
|
commit('setProjects', projects); // Then with summaries
|
||||||
}
|
}
|
||||||
commit('clearProjectsLoading');
|
commit('clearProjectsLoading');
|
||||||
dispatch('prepareGroups');
|
dispatch('prepareGroups');
|
||||||
|
|||||||
Reference in New Issue
Block a user