optimize stores hydration calls (#16591)

This commit is contained in:
Azri Kahar
2022-11-24 06:24:20 +08:00
committed by GitHub
parent 8a3dc4b68b
commit ecb0998a8f
4 changed files with 13 additions and 17 deletions

View File

@@ -185,21 +185,18 @@ export default defineComponent({
async function deleteAndQuit() {
await remove();
await collectionsStore.hydrate();
await fieldsStore.hydrate();
await Promise.all([collectionsStore.hydrate(), fieldsStore.hydrate()]);
router.replace(`/settings/data-model`);
}
async function saveAndStay() {
await save();
await collectionsStore.hydrate();
await fieldsStore.hydrate();
await Promise.all([collectionsStore.hydrate(), fieldsStore.hydrate()]);
}
async function saveAndQuit() {
await save();
await collectionsStore.hydrate();
await fieldsStore.hydrate();
await Promise.all([collectionsStore.hydrate(), fieldsStore.hydrate()]);
router.push(`/settings/data-model`);
}

View File

@@ -252,18 +252,18 @@ export default defineComponent({
},
});
const storeHydrations: Promise<void>[] = [];
const relations = getSystemRelations();
if (relations.length > 0) {
for (const relation of relations) {
await api.post('/relations', relation);
}
await relationsStore.hydrate();
const requests = relations.map((relation) => api.post('/relations', relation));
await Promise.all(requests);
storeHydrations.push(relationsStore.hydrate());
}
await collectionsStore.hydrate();
await fieldsStore.hydrate();
storeHydrations.push(collectionsStore.hydrate(), fieldsStore.hydrate());
await Promise.all(storeHydrations);
notify({
title: t('collection_created'),

View File

@@ -446,8 +446,7 @@ export default defineComponent({
if (newLang && newLang !== locale.value) {
await setLanguage(newLang);
await fieldsStore.hydrate();
await collectionsStore.hydrate();
await Promise.all([fieldsStore.hydrate(), collectionsStore.hydrate()]);
}
}

View File

@@ -165,8 +165,8 @@ export const useCollectionsStore = defineStore({
try {
await api.delete(`/collections/${collection}`);
await this.hydrate();
await relationsStore.hydrate();
await Promise.all([this.hydrate(), relationsStore.hydrate()]);
notify({
title: i18n.global.t('delete_collection_success'),
});