Browse Source

fix: add an option skip meta get if missing in cache

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5936/head
Pranav C 1 year ago
parent
commit
e22a3cd19c
  1. 4
      packages/nc-gui/components/smartsheet/Grid.vue
  2. 3
      packages/nc-gui/composables/useMetas.ts

4
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,

3
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<TableType | null> => {
const getMeta = async (tableIdOrTitle: string, force = false, skipIfCacheMiss = false): Promise<TableType | null> => {
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

Loading…
Cancel
Save