From 2bea06b6332aa5a16edab972d518e23b80d2a08e Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 13 Jan 2024 17:18:46 +0000 Subject: [PATCH] fix: cache key --- packages/nocodb/src/helpers/PagedResponse.ts | 2 +- packages/nocodb/src/models/Base.ts | 33 ++++++++++++-------- packages/nocodb/src/models/Model.ts | 6 ++-- packages/nocodb/src/models/View.ts | 6 ++-- packages/nocodb/src/utils/globals.ts | 3 ++ 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/packages/nocodb/src/helpers/PagedResponse.ts b/packages/nocodb/src/helpers/PagedResponse.ts index c1e606a1d2..09d4e35f82 100644 --- a/packages/nocodb/src/helpers/PagedResponse.ts +++ b/packages/nocodb/src/helpers/PagedResponse.ts @@ -1,6 +1,6 @@ import { extractLimitAndOffset } from '.'; import type { PaginatedType } from 'nocodb-sdk'; -import {NcError} from "~/helpers/catchError"; +import { NcError } from '~/helpers/catchError'; export class PagedResponseImpl { constructor( diff --git a/packages/nocodb/src/models/Base.ts b/packages/nocodb/src/models/Base.ts index 61fc986e84..876ff09333 100644 --- a/packages/nocodb/src/models/Base.ts +++ b/packages/nocodb/src/models/Base.ts @@ -201,13 +201,14 @@ export default class Base implements BaseType { if (o) { // delete : await NocoCache.del(`${CacheScope.PROJECT}:${baseId}`); + await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:${baseId}`); // delete : - await NocoCache.del(`${CacheScope.PROJECT}:${o.title}`); + await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:${o.title}`); // delete <scope>:<uuid> - await NocoCache.del(`${CacheScope.PROJECT}:${o.uuid}`); + await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:${o.uuid}`); // delete <scope>:ref:<titleOfId> - await NocoCache.del(`${CacheScope.PROJECT}:ref:${o.title}`); - await NocoCache.del(`${CacheScope.PROJECT}:ref:${o.id}`); + await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:ref:${o.title}`); + await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:ref:${o.id}`); } await NocoCache.del(CacheScope.INSTANCE_META); @@ -334,8 +335,8 @@ export default class Base implements BaseType { const baseId = uuid && (await NocoCache.get( - `${CacheScope.PROJECT}:${uuid}`, - CacheGetType.TYPE_OBJECT, + `${CacheScope.PROJECT_ALIAS}:${uuid}`, + CacheGetType.TYPE_STRING, )); let baseData = null; if (!baseId) { @@ -344,7 +345,10 @@ export default class Base implements BaseType { }); if (baseData) { baseData.meta = parseMetaProp(baseData); - await NocoCache.set(`${CacheScope.PROJECT}:${uuid}`, baseData?.id); + await NocoCache.set( + `${CacheScope.PROJECT_ALIAS}:${uuid}`, + baseData?.id, + ); } } else { return this.get(baseId); @@ -365,8 +369,8 @@ export default class Base implements BaseType { const baseId = title && (await NocoCache.get( - `${CacheScope.PROJECT}:${title}`, - CacheGetType.TYPE_OBJECT, + `${CacheScope.PROJECT_ALIAS}:${title}`, + CacheGetType.TYPE_STRING, )); let baseData = null; if (!baseId) { @@ -376,7 +380,10 @@ export default class Base implements BaseType { }); if (baseData) { baseData.meta = parseMetaProp(baseData); - await NocoCache.set(`${CacheScope.PROJECT}:${title}`, baseData?.id); + await NocoCache.set( + `${CacheScope.PROJECT_ALIAS}:${title}`, + baseData?.id, + ); } } else { return this.get(baseId); @@ -388,8 +395,8 @@ export default class Base implements BaseType { const baseId = titleOrId && (await NocoCache.get( - `${CacheScope.PROJECT}:ref:${titleOrId}`, - CacheGetType.TYPE_OBJECT, + `${CacheScope.PROJECT_ALIAS}:ref:${titleOrId}`, + CacheGetType.TYPE_STRING, )); let baseData = null; if (!baseId) { @@ -422,7 +429,7 @@ export default class Base implements BaseType { baseData.meta = parseMetaProp(baseData); await NocoCache.set( - `${CacheScope.PROJECT}:ref:${titleOrId}`, + `${CacheScope.PROJECT_ALIAS}:ref:${titleOrId}`, baseData?.id, ); } diff --git a/packages/nocodb/src/models/Model.ts b/packages/nocodb/src/models/Model.ts index ebe5ad416e..d8e2721b4b 100644 --- a/packages/nocodb/src/models/Model.ts +++ b/packages/nocodb/src/models/Model.ts @@ -847,12 +847,12 @@ export default class Model implements TableType { ncMeta = Noco.ncMeta, ) { const cacheKey = source_id - ? `${CacheScope.MODEL}:${base_id}:${source_id}:${aliasOrId}` - : `${CacheScope.MODEL}:${base_id}:${aliasOrId}`; + ? `${CacheScope.MODEL_ALIAS}:${base_id}:${source_id}:${aliasOrId}` + : `${CacheScope.MODEL_ALIAS}:${base_id}:${aliasOrId}`; const modelId = base_id && aliasOrId && - (await NocoCache.get(cacheKey, CacheGetType.TYPE_OBJECT)); + (await NocoCache.get(cacheKey, CacheGetType.TYPE_STRING)); if (!modelId) { const model = source_id ? await ncMeta.metaGet2( diff --git a/packages/nocodb/src/models/View.ts b/packages/nocodb/src/models/View.ts index 51e06faeef..8cc55b1a9e 100644 --- a/packages/nocodb/src/models/View.ts +++ b/packages/nocodb/src/models/View.ts @@ -158,8 +158,8 @@ export default class View implements ViewType { const viewId = titleOrId && (await NocoCache.get( - `${CacheScope.VIEW}:${fk_model_id}:${titleOrId}`, - CacheGetType.TYPE_OBJECT, + `${CacheScope.VIEW_ALIAS}:${fk_model_id}:${titleOrId}`, + CacheGetType.TYPE_STRING, )); if (!viewId) { const view = await ncMeta.metaGet2( @@ -192,7 +192,7 @@ export default class View implements ViewType { view.meta = parseMetaProp(view); // todo: cache - titleOrId can be viewId so we need a different scope here await NocoCache.set( - `${CacheScope.VIEW}:${fk_model_id}:${titleOrId}`, + `${CacheScope.VIEW_ALIAS}:${fk_model_id}:${titleOrId}`, view.id, ); } diff --git a/packages/nocodb/src/utils/globals.ts b/packages/nocodb/src/utils/globals.ts index 0a4e570951..9d9f712241 100644 --- a/packages/nocodb/src/utils/globals.ts +++ b/packages/nocodb/src/utils/globals.ts @@ -159,6 +159,9 @@ export enum CacheScope { JOBS = 'nc_jobs', PRESIGNED_URL = 'presignedUrl', STORE = 'store', + PROJECT_ALIAS = 'baseAlias', + MODEL_ALIAS = 'modelAlias', + VIEW_ALIAS = 'viewAlias', } export enum CacheGetType {