Browse Source

fix: base cache

pull/7464/head
mertmit 10 months ago
parent
commit
5b55db280c
  1. 44
      packages/nocodb/src/models/Base.ts

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

@ -175,7 +175,10 @@ export default class Base implements BaseType {
await NocoCache.set(`${CacheScope.PROJECT}:${baseId}`, baseData); await NocoCache.set(`${CacheScope.PROJECT}:${baseId}`, baseData);
} }
if (baseData?.uuid) { if (baseData?.uuid) {
await NocoCache.set(`${CacheScope.PROJECT}:${baseData.uuid}`, baseId); await NocoCache.set(
`${CacheScope.PROJECT_ALIAS}:${baseData.uuid}`,
baseId,
);
} }
} else { } else {
if (baseData?.deleted) { if (baseData?.deleted) {
@ -200,16 +203,15 @@ export default class Base implements BaseType {
const key = `${CacheScope.PROJECT}:${baseId}`; const key = `${CacheScope.PROJECT}:${baseId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) { if (o) {
// delete <scope>:<id>
await NocoCache.del(`${CacheScope.PROJECT}:${baseId}`);
await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:${baseId}`);
// delete <scope>:<title> // delete <scope>:<title>
await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:${o.title}`);
// delete <scope>:<uuid> // delete <scope>:<uuid>
await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:${o.uuid}`);
// delete <scope>:ref:<titleOfId> // delete <scope>:ref:<titleOfId>
await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:ref:${o.title}`); await NocoCache.del([
await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:ref:${o.id}`); `${CacheScope.PROJECT_ALIAS}:${o.title}`,
`${CacheScope.PROJECT_ALIAS}:${o.uuid}`,
`${CacheScope.PROJECT_ALIAS}:ref:${o.title}`,
`${CacheScope.PROJECT_ALIAS}:ref:${o.id}`,
]);
} }
await NocoCache.del(CacheScope.INSTANCE_META); await NocoCache.del(CacheScope.INSTANCE_META);
@ -258,16 +260,22 @@ export default class Base implements BaseType {
// update data // update data
// new uuid is generated // new uuid is generated
if (o.uuid && updateObj.uuid && o.uuid !== updateObj.uuid) { if (o.uuid && updateObj.uuid && o.uuid !== updateObj.uuid) {
await NocoCache.del(`${CacheScope.PROJECT}:${o.uuid}`); await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:${o.uuid}`);
await NocoCache.set(`${CacheScope.PROJECT}:${updateObj.uuid}`, baseId); await NocoCache.set(
`${CacheScope.PROJECT_ALIAS}:${updateObj.uuid}`,
baseId,
);
} }
// disable shared base // disable shared base
if (o.uuid && updateObj.uuid === null) { if (o.uuid && updateObj.uuid === null) {
await NocoCache.del(`${CacheScope.PROJECT}:${o.uuid}`); await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:${o.uuid}`);
} }
if (o.title && updateObj.title && o.title !== updateObj.title) { if (o.title && updateObj.title && o.title !== updateObj.title) {
await NocoCache.del(`${CacheScope.PROJECT}:${o.title}`); await NocoCache.del(`${CacheScope.PROJECT_ALIAS}:${o.title}`);
await NocoCache.set(`${CacheScope.PROJECT}:${updateObj.title}`, baseId); await NocoCache.set(
`${CacheScope.PROJECT_ALIAS}:${updateObj.title}`,
baseId,
);
} }
o = { ...o, ...updateObj }; o = { ...o, ...updateObj };
@ -311,12 +319,14 @@ export default class Base implements BaseType {
if (base) { if (base) {
// delete <scope>:<uuid> // delete <scope>:<uuid>
await NocoCache.del(`${CacheScope.PROJECT}:${base.uuid}`);
// delete <scope>:<title> // delete <scope>:<title>
await NocoCache.del(`${CacheScope.PROJECT}:${base.title}`);
// delete <scope>:ref:<titleOfId> // delete <scope>:ref:<titleOfId>
await NocoCache.del(`${CacheScope.PROJECT}:ref:${base.title}`); await NocoCache.del([
await NocoCache.del(`${CacheScope.PROJECT}:ref:${base.id}`); `${CacheScope.PROJECT_ALIAS}:${base.uuid}`,
`${CacheScope.PROJECT_ALIAS}:${base.title}`,
`${CacheScope.PROJECT_ALIAS}:ref:${base.title}`,
`${CacheScope.PROJECT_ALIAS}:ref:${base.id}`,
]);
} }
await NocoCache.deepDel( await NocoCache.deepDel(

Loading…
Cancel
Save