Skip to content

Commit 4a21b08

Browse files
committed
feat(ui): parallel loading of template data
1 parent b3b3688 commit 4a21b08

File tree

3 files changed

+35
-53
lines changed

3 files changed

+35
-53
lines changed

web/src/components/NewTaskDialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
>
1010
<template v-slot:title={}>
1111
<v-icon small class="mr-4">{{ TEMPLATE_TYPE_ICONS[template?.type || ''] }}</v-icon>
12-
<span class="breadcrumbs__item">{{ template?.alias || '' }}</span>
12+
<span class="breadcrumbs__item">{{ template?.name || '' }}</span>
1313
<v-icon>mdi-chevron-right</v-icon>
1414
<span class="breadcrumbs__item">{{ $t('newTask') }}</span>
1515
</template>

web/src/components/ProjectMixin.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ export default {
66
},
77

88
methods: {
9-
async loadProjectResources(name) {
9+
async loadProjectEndpoint(endpoint) {
1010
return (await axios({
1111
method: 'get',
12-
url: `/api/project/${this.projectId}/${name}`,
12+
url: `/api/project/${this.projectId}${endpoint}`,
1313
responseType: 'json',
1414
})).data;
1515
},
16+
17+
async loadProjectResources(name) {
18+
return this.loadProjectEndpoint(`/${name}`);
19+
},
20+
1621
async loadProjectResource(name, id) {
17-
return (await axios({
18-
method: 'get',
19-
url: `/api/project/${this.projectId}/${name}/${id}`,
20-
responseType: 'json',
21-
})).data;
22+
return this.loadProjectEndpoint(`/${name}/${id}`);
2223
},
2324
},
2425
};

web/src/components/TemplateForm.vue

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,7 @@ export default {
606606
607607
async afterLoadData() {
608608
if (this.sourceItemId) {
609-
const item = (await axios({
610-
url: `/api/project/${this.projectId}/templates/${this.sourceItemId}`,
611-
responseType: 'json',
612-
})).data;
609+
const item = await this.loadProjectResource('templates', this.sourceItemId);
613610
614611
item.id = null;
615612
@@ -619,10 +616,7 @@ export default {
619616
}
620617
}
621618
622-
const sourceSchedule = (await axios({
623-
url: `/api/project/${this.projectId}/templates/${this.sourceItemId}/schedules`,
624-
responseType: 'json',
625-
})).data[0];
619+
const sourceSchedule = (await this.loadProjectEndpoint(`/templates/${this.sourceItemId}/schedules`))[0];
626620
627621
if (sourceSchedule != null) {
628622
this.cronFormat = sourceSchedule.cron_format;
@@ -637,36 +631,33 @@ export default {
637631
this.item.task_params = {};
638632
}
639633
640-
this.repositories = (await axios({
641-
url: `/api/project/${this.projectId}/repositories`,
642-
responseType: 'json',
643-
})).data;
644-
645-
this.inventory = [
646-
...(await axios({
647-
url: `/api/project/${this.projectId}/inventory?app=${this.app}&template_id=${this.itemId}`,
648-
responseType: 'json',
649-
})).data,
650-
651-
...(await axios({
652-
url: `/api/project/${this.projectId}/inventory?app=${this.app}`,
653-
responseType: 'json',
654-
})).data,
655-
];
656-
657-
this.environment = (await axios({
658-
url: `/api/project/${this.projectId}/environment`,
659-
responseType: 'json',
660-
})).data;
661-
662-
const template = (await axios({
663-
url: `/api/project/${this.projectId}/templates`,
664-
responseType: 'json',
665-
})).data;
634+
let templates;
635+
let inventory1;
636+
let inventory2;
637+
638+
[
639+
this.repositories,
640+
inventory1,
641+
inventory2,
642+
this.schedules,
643+
this.views,
644+
this.environment,
645+
templates,
646+
] = await Promise.all([
647+
this.loadProjectResources('repositories'),
648+
this.loadProjectEndpoint(`/inventory?app=${this.app}&template_id=${this.itemId}`),
649+
this.loadProjectEndpoint(`/inventory?app=${this.app}`),
650+
this.isNew ? [] : this.loadProjectEndpoint(`/templates/${this.itemId}/schedules`),
651+
this.loadProjectResources('views'),
652+
this.loadProjectResources('environment'),
653+
this.loadProjectResources('templates'),
654+
]);
655+
656+
this.inventory = [...inventory1, ...inventory2];
666657
667658
const builds = [];
668659
const deploys = [];
669-
template.forEach((t) => {
660+
templates.forEach((t) => {
670661
switch (t.type) {
671662
case 'build':
672663
if (builds.length === 0) {
@@ -693,16 +684,6 @@ export default {
693684
}
694685
this.buildTemplates.push(...deploys);
695686
696-
this.schedules = this.isNew ? [] : (await axios({
697-
url: `/api/project/${this.projectId}/templates/${this.itemId}/schedules`,
698-
responseType: 'json',
699-
})).data;
700-
701-
this.views = (await axios({
702-
url: `/api/project/${this.projectId}/views`,
703-
responseType: 'json',
704-
})).data;
705-
706687
if (this.schedules.length > 0) {
707688
const schedule = this.schedules.find((s) => s.repository_id != null);
708689
if (schedule != null) {

0 commit comments

Comments
 (0)