Browse Source

Merge pull request #7465 from nocodb/nc-fix/cache-key

fix: cache key
pull/7469/head
Mert E 10 months ago committed by GitHub
parent
commit
3b0988e25f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 33
      packages/nocodb/src/models/Base.ts
  2. 6
      packages/nocodb/src/models/Model.ts
  3. 6
      packages/nocodb/src/models/View.ts
  4. 3
      packages/nocodb/src/utils/globals.ts

33
packages/nocodb/src/models/Base.ts

@ -201,13 +201,14 @@ export default class Base implements BaseType {
if (o) { if (o) {
// delete <scope>:<id> // delete <scope>:<id>
await NocoCache.del(`${CacheScope.PROJECT}:${baseId}`); await NocoCache.del(`${CacheScope.PROJECT}:${baseId}`);
await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:${baseId}`);
// delete <scope>:<title> // delete <scope>:<title>
await NocoCache.del(`${CacheScope.PROJECT}:${o.title}`); await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:${o.title}`);
// delete <scope>:<uuid> // delete <scope>:<uuid>
await NocoCache.del(`${CacheScope.PROJECT}:${o.uuid}`); await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:${o.uuid}`);
// delete <scope>:ref:<titleOfId> // delete <scope>:ref:<titleOfId>
await NocoCache.del(`${CacheScope.PROJECT}:ref:${o.title}`); await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:ref:${o.title}`);
await NocoCache.del(`${CacheScope.PROJECT}:ref:${o.id}`); await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:ref:${o.id}`);
} }
await NocoCache.del(CacheScope.INSTANCE_META); await NocoCache.del(CacheScope.INSTANCE_META);
@ -334,8 +335,8 @@ export default class Base implements BaseType {
const baseId = const baseId =
uuid && uuid &&
(await NocoCache.get( (await NocoCache.get(
`${CacheScope.PROJECT}:${uuid}`, `${CacheScope.PROJECT_ALIAS}:${uuid}`,
CacheGetType.TYPE_OBJECT, CacheGetType.TYPE_STRING,
)); ));
let baseData = null; let baseData = null;
if (!baseId) { if (!baseId) {
@ -344,7 +345,10 @@ export default class Base implements BaseType {
}); });
if (baseData) { if (baseData) {
baseData.meta = parseMetaProp(baseData); baseData.meta = parseMetaProp(baseData);
await NocoCache.set(`${CacheScope.PROJECT}:${uuid}`, baseData?.id); await NocoCache.set(
`${CacheScope.PROJECT_ALIAS}:${uuid}`,
baseData?.id,
);
} }
} else { } else {
return this.get(baseId); return this.get(baseId);
@ -365,8 +369,8 @@ export default class Base implements BaseType {
const baseId = const baseId =
title && title &&
(await NocoCache.get( (await NocoCache.get(
`${CacheScope.PROJECT}:${title}`, `${CacheScope.PROJECT_ALIAS}:${title}`,
CacheGetType.TYPE_OBJECT, CacheGetType.TYPE_STRING,
)); ));
let baseData = null; let baseData = null;
if (!baseId) { if (!baseId) {
@ -376,7 +380,10 @@ export default class Base implements BaseType {
}); });
if (baseData) { if (baseData) {
baseData.meta = parseMetaProp(baseData); baseData.meta = parseMetaProp(baseData);
await NocoCache.set(`${CacheScope.PROJECT}:${title}`, baseData?.id); await NocoCache.set(
`${CacheScope.PROJECT_ALIAS}:${title}`,
baseData?.id,
);
} }
} else { } else {
return this.get(baseId); return this.get(baseId);
@ -388,8 +395,8 @@ export default class Base implements BaseType {
const baseId = const baseId =
titleOrId && titleOrId &&
(await NocoCache.get( (await NocoCache.get(
`${CacheScope.PROJECT}:ref:${titleOrId}`, `${CacheScope.PROJECT_ALIAS}:ref:${titleOrId}`,
CacheGetType.TYPE_OBJECT, CacheGetType.TYPE_STRING,
)); ));
let baseData = null; let baseData = null;
if (!baseId) { if (!baseId) {
@ -422,7 +429,7 @@ export default class Base implements BaseType {
baseData.meta = parseMetaProp(baseData); baseData.meta = parseMetaProp(baseData);
await NocoCache.set( await NocoCache.set(
`${CacheScope.PROJECT}:ref:${titleOrId}`, `${CacheScope.PROJECT_ALIAS}:ref:${titleOrId}`,
baseData?.id, baseData?.id,
); );
} }

6
packages/nocodb/src/models/Model.ts

@ -844,12 +844,12 @@ export default class Model implements TableType {
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
const cacheKey = source_id const cacheKey = source_id
? `${CacheScope.MODEL}:${base_id}:${source_id}:${aliasOrId}` ? `${CacheScope.MODEL_ALIAS}:${base_id}:${source_id}:${aliasOrId}`
: `${CacheScope.MODEL}:${base_id}:${aliasOrId}`; : `${CacheScope.MODEL_ALIAS}:${base_id}:${aliasOrId}`;
const modelId = const modelId =
base_id && base_id &&
aliasOrId && aliasOrId &&
(await NocoCache.get(cacheKey, CacheGetType.TYPE_OBJECT)); (await NocoCache.get(cacheKey, CacheGetType.TYPE_STRING));
if (!modelId) { if (!modelId) {
const model = source_id const model = source_id
? await ncMeta.metaGet2( ? await ncMeta.metaGet2(

6
packages/nocodb/src/models/View.ts

@ -158,8 +158,8 @@ export default class View implements ViewType {
const viewId = const viewId =
titleOrId && titleOrId &&
(await NocoCache.get( (await NocoCache.get(
`${CacheScope.VIEW}:${fk_model_id}:${titleOrId}`, `${CacheScope.VIEW_ALIAS}:${fk_model_id}:${titleOrId}`,
CacheGetType.TYPE_OBJECT, CacheGetType.TYPE_STRING,
)); ));
if (!viewId) { if (!viewId) {
const view = await ncMeta.metaGet2( const view = await ncMeta.metaGet2(
@ -192,7 +192,7 @@ export default class View implements ViewType {
view.meta = parseMetaProp(view); view.meta = parseMetaProp(view);
// todo: cache - titleOrId can be viewId so we need a different scope here // todo: cache - titleOrId can be viewId so we need a different scope here
await NocoCache.set( await NocoCache.set(
`${CacheScope.VIEW}:${fk_model_id}:${titleOrId}`, `${CacheScope.VIEW_ALIAS}:${fk_model_id}:${titleOrId}`,
view.id, view.id,
); );
} }

3
packages/nocodb/src/utils/globals.ts

@ -159,6 +159,9 @@ export enum CacheScope {
JOBS = 'nc_jobs', JOBS = 'nc_jobs',
PRESIGNED_URL = 'presignedUrl', PRESIGNED_URL = 'presignedUrl',
STORE = 'store', STORE = 'store',
PROJECT_ALIAS = 'baseAlias',
MODEL_ALIAS = 'modelAlias',
VIEW_ALIAS = 'viewAlias',
} }
export enum CacheGetType { export enum CacheGetType {

Loading…
Cancel
Save