Skip to content

Commit 266268d

Browse files
committed
fix(ui): do not load tasks data twice
1 parent b6a0c2b commit 266268d

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

web/src/App.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
</div>
7878
</template>
7979
<template v-slot:form="{}">
80-
<TaskLogView :project-id="projectId" :item-id="task ? task.id : null"/>
80+
<TaskLogView :project-id="projectId" :item="task" />
8181
</template>
8282
</EditDialog>
8383

@@ -1021,6 +1021,7 @@ export default {
10211021
if (parseInt(this.$route.query.t || '', 10) !== e.taskId) {
10221022
const query = { ...this.$route.query, t: e.taskId };
10231023
await this.$router.replace({ query });
1024+
return; // router has watcher and emits `i-show-task` again after load.
10241025
}
10251026
10261027
this.task = (await axios({

web/src/components/TaskLogView.vue

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,21 @@ import TaskStatus from '@/components/TaskStatus.vue';
207207
import socket from '@/socket';
208208
import VirtualList from 'vue-virtual-scroll-list';
209209
import TaskLogViewRecord from '@/components/TaskLogViewRecord.vue';
210+
import ProjectMixin from '@/components/ProjectMixin';
210211
211212
export default {
212213
components: { TaskStatus, VirtualList },
214+
215+
mixins: [ProjectMixin],
216+
213217
props: {
214-
itemId: Number,
218+
item: Object,
215219
projectId: Number,
216220
},
221+
217222
data() {
218223
return {
219224
itemComponent: TaskLogViewRecord,
220-
item: {},
221225
output: [],
222226
outputBuffer: [],
223227
user: {},
@@ -238,6 +242,10 @@ export default {
238242
},
239243
240244
computed: {
245+
itemId() {
246+
return this.item?.id;
247+
},
248+
241249
isTaskStopped() {
242250
return [
243251
'stopped',
@@ -334,7 +342,6 @@ export default {
334342
},
335343
336344
reset() {
337-
this.item = {};
338345
this.output = [];
339346
this.outputBuffer = [];
340347
this.outputInterval = null;
@@ -358,40 +365,33 @@ export default {
358365
...data,
359366
id: data.time + data.output,
360367
});
361-
362-
// this.$nextTick(() => {
363-
// if (this.$refs.records) {
364-
// this.$refs.records.scrollToBottom();
365-
// }
366-
// });
367-
368368
break;
369369
default:
370370
break;
371371
}
372372
},
373373
374374
async loadData() {
375-
this.item = (await axios({
376-
method: 'get',
377-
url: `/api/project/${this.projectId}/tasks/${this.itemId}`,
378-
responseType: 'json',
379-
})).data;
380-
381-
this.output = (await axios({
382-
method: 'get',
383-
url: `/api/project/${this.projectId}/tasks/${this.itemId}/output`,
384-
responseType: 'json',
385-
})).data.map((item) => ({
386-
...item,
387-
id: item.time + item.output,
388-
}));
389-
390-
this.user = this.item.user_id ? (await axios({
391-
method: 'get',
392-
url: `/api/users/${this.item.user_id}`,
393-
responseType: 'json',
394-
})).data : null;
375+
[
376+
this.output,
377+
this.user,
378+
] = await Promise.all([
379+
380+
(await axios({
381+
method: 'get',
382+
url: `/api/project/${this.projectId}/tasks/${this.itemId}/output`,
383+
responseType: 'json',
384+
})).data.map((item) => ({
385+
...item,
386+
id: item.time + item.output,
387+
})),
388+
389+
this.item.user_id ? (await axios({
390+
method: 'get',
391+
url: `/api/users/${this.item.user_id}`,
392+
responseType: 'json',
393+
})).data : null,
394+
]);
395395
},
396396
},
397397
};

0 commit comments

Comments
 (0)