Browse Source

fix: avoid using del on updating model

pull/7727/head
mertmit 9 months ago
parent
commit
67fffb2076
  1. 17
      packages/nocodb/src/models/BaseUser.ts
  2. 9
      packages/nocodb/src/models/Source.ts

17
packages/nocodb/src/models/BaseUser.ts

@ -3,7 +3,7 @@ import type { BaseType } from 'nocodb-sdk';
import type User from '~/models/User';
import Base from '~/models/Base';
import {
// CacheDelDirection,
CacheDelDirection,
CacheGetType,
CacheScope,
MetaTable,
@ -245,8 +245,13 @@ export default class BaseUser {
base_id: baseId,
});
// delete cache
await NocoCache.del(key);
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update data
o = { ...o, ...updateObj };
// set cache
await NocoCache.set(key, o);
}
// cache and return
return await this.get(baseId, userId, ncMeta);
@ -265,8 +270,10 @@ export default class BaseUser {
);
// delete list cache to refresh list
await NocoCache.del(`${CacheScope.BASE_USER}:${baseId}:${userId}`);
await NocoCache.del(`${CacheScope.BASE_USER}:${baseId}:list`);
await NocoCache.deepDel(
`${CacheScope.BASE_USER}:${baseId}:${userId}`,
CacheDelDirection.CHILD_TO_PARENT,
);
return response;
}

9
packages/nocodb/src/models/Source.ts

@ -147,7 +147,14 @@ export default class Source implements SourceType {
oldBase.id,
);
await NocoCache.del(`${CacheScope.BASE}:${sourceId}`);
const cacheKey = `${CacheScope.BASE}:${sourceId}`;
let o = await NocoCache.get(cacheKey, CacheGetType.TYPE_OBJECT);
if (o) {
// update data
o = { ...o, ...updateObj };
// set cache
await NocoCache.set(cacheKey, o);
}
// call before reorder to update cache
const returnBase = await this.get(oldBase.id, false, ncMeta);

Loading…
Cancel
Save