Browse Source

fix: use <scope>:ref:<titleOfId> instead

Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com>
pull/1854/head
Wing-Kam Wong 3 years ago
parent
commit
0a7e2e9608
  1. 30
      packages/nocodb/src/lib/noco-models/Project.ts

30
packages/nocodb/src/lib/noco-models/Project.ts

@ -179,13 +179,16 @@ export default class Project implements ProjectType {
// get existing cache // get existing cache
const key = `${CacheScope.PROJECT}:${projectId}`; const key = `${CacheScope.PROJECT}:${projectId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o?.uuid) { if (o) {
await NocoCache.del(`${CacheScope.PROJECT}:${o.uuid}`); // delete <scope>:<id>
} await NocoCache.del(`${CacheScope.PROJECT}:${projectId}`);
if (o) await NocoCache.del(`${CacheScope.PROJECT}:${projectId}`); // delete <scope>:<title>
if (o?.title) {
await NocoCache.del(`${CacheScope.PROJECT}:${o.title}`); await NocoCache.del(`${CacheScope.PROJECT}:${o.title}`);
// delete <scope>:<uuid>
await NocoCache.del(`${CacheScope.PROJECT}:${o.uuid}`);
// delete <scope>:ref:<titleOfId>
await NocoCache.del(`${CacheScope.PROJECT}:ref:${o.title}`);
await NocoCache.del(`${CacheScope.PROJECT}:ref:${o.id}`);
} }
// remove item in cache list // remove item in cache list
@ -264,12 +267,17 @@ export default class Project implements ProjectType {
await base.delete(ncMeta); await base.delete(ncMeta);
} }
const project = await this.get(projectId); const project = await this.get(projectId);
if (project.uuid) {
if (project) {
// delete <scope>:<uuid>
await NocoCache.del(`${CacheScope.PROJECT}:${project.uuid}`); await NocoCache.del(`${CacheScope.PROJECT}:${project.uuid}`);
} // delete <scope>:<title>
if (project.title) {
await NocoCache.del(`${CacheScope.PROJECT}:${project.title}`); await NocoCache.del(`${CacheScope.PROJECT}:${project.title}`);
// delete <scope>:ref:<titleOfId>
await NocoCache.del(`${CacheScope.PROJECT}:ref:${project.title}`);
await NocoCache.del(`${CacheScope.PROJECT}:ref:${project.id}`);
} }
await NocoCache.deepDel( await NocoCache.deepDel(
CacheScope.PROJECT, CacheScope.PROJECT,
`${CacheScope.PROJECT}:${projectId}`, `${CacheScope.PROJECT}:${projectId}`,
@ -328,7 +336,7 @@ export default class Project implements ProjectType {
const projectId = const projectId =
titleOrId && titleOrId &&
(await NocoCache.get( (await NocoCache.get(
`${CacheScope.PROJECT}:${titleOrId}`, `${CacheScope.PROJECT}:ref:${titleOrId}`,
CacheGetType.TYPE_OBJECT CacheGetType.TYPE_OBJECT
)); ));
let projectData = null; let projectData = null;
@ -357,7 +365,7 @@ export default class Project implements ProjectType {
} }
); );
await NocoCache.set( await NocoCache.set(
`${CacheScope.PROJECT}:${titleOrId}`, `${CacheScope.PROJECT}:ref:${titleOrId}`,
projectData?.id projectData?.id
); );
} else { } else {

Loading…
Cancel
Save