From e22a3cd19c91c7cfc1a0f47958707ac9e916a3f6 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 21 Jun 2023 16:38:43 +0530 Subject: [PATCH] fix: add an option skip meta get if missing in cache Signed-off-by: Pranav C --- packages/nc-gui/components/smartsheet/Grid.vue | 4 ++-- packages/nc-gui/composables/useMetas.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/Grid.vue b/packages/nc-gui/components/smartsheet/Grid.vue index 5a4595e7bb..1940aada59 100644 --- a/packages/nc-gui/components/smartsheet/Grid.vue +++ b/packages/nc-gui/components/smartsheet/Grid.vue @@ -768,7 +768,7 @@ onBeforeUnmount(async () => { const viewMetaValue = view.value const dataValue = data.value if (viewMetaValue) { - getMeta(viewMetaValue.fk_model_id).then((res) => { + getMeta(viewMetaValue.fk_model_id, false, true).then((res) => { const metaValue = res if (!metaValue) return saveOrUpdateRecords({ @@ -815,7 +815,7 @@ watch( switchingTab.value = true // whenever tab changes or view changes save any unsaved data if (old?.id) { - const oldMeta = await getMeta(old.fk_model_id!) + const oldMeta = await getMeta(old.fk_model_id!, false, true) if (oldMeta) { await saveOrUpdateRecords({ viewMetaValue: old, diff --git a/packages/nc-gui/composables/useMetas.ts b/packages/nc-gui/composables/useMetas.ts index 72cde33128..31f7931519 100644 --- a/packages/nc-gui/composables/useMetas.ts +++ b/packages/nc-gui/composables/useMetas.ts @@ -26,7 +26,7 @@ export function useMetas() { } // todo: this needs a proper refactor, arbitrary waiting times are usually not a good idea - const getMeta = async (tableIdOrTitle: string, force = false): Promise => { + const getMeta = async (tableIdOrTitle: string, force = false, skipIfCacheMiss = false): Promise => { if (!tableIdOrTitle) return null /** wait until loading is finished if requesting same meta */ if (!force && loadingState.value[tableIdOrTitle]) { @@ -58,6 +58,7 @@ export function useMetas() { return metas.value[tableIdOrTitle] } } + if (skipIfCacheMiss) return null loadingState.value[tableIdOrTitle] = true