From d298a195ccf022c3d0a79a8848bd2f941a8c143b Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 23 May 2023 19:17:52 +0800 Subject: [PATCH] fix(nocodb): cater cases where baseId is not required --- packages/nocodb/src/models/Model.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/nocodb/src/models/Model.ts b/packages/nocodb/src/models/Model.ts index dcc33c0fe3..b2be488918 100644 --- a/packages/nocodb/src/models/Model.ts +++ b/packages/nocodb/src/models/Model.ts @@ -135,10 +135,18 @@ export default class Model implements TableType { MetaTable.MODELS, insertObj, ); - + if (baseId) { + await NocoCache.appendToList( + CacheScope.MODEL, + [projectId, baseId], + `${CacheScope.MODEL}:${id}`, + ); + } + // cater cases where baseId is not required + // e.g. xcVisibilityMetaGet await NocoCache.appendToList( CacheScope.MODEL, - [projectId, baseId], + [projectId], `${CacheScope.MODEL}:${id}`, ); @@ -690,13 +698,13 @@ export default class Model implements TableType { }, ncMeta = Noco.ncMeta, ) { + const cacheKey = base_id + ? `${CacheScope.MODEL}:${project_id}:${base_id}:${aliasOrId}` + : `${CacheScope.MODEL}:${project_id}:${aliasOrId}`; const modelId = project_id && aliasOrId && - (await NocoCache.get( - `${CacheScope.MODEL}:${project_id}:${aliasOrId}`, - CacheGetType.TYPE_OBJECT, - )); + (await NocoCache.get(cacheKey, CacheGetType.TYPE_OBJECT)); if (!modelId) { const model = base_id ? await ncMeta.metaGet2( @@ -742,10 +750,7 @@ export default class Model implements TableType { }, ); if (model) { - await NocoCache.set( - `${CacheScope.MODEL}:${project_id}:${aliasOrId}`, - model.id, - ); + await NocoCache.set(cacheKey, model.id); await NocoCache.set(`${CacheScope.MODEL}:${model.id}`, model); } return model && new Model(model);