Browse Source

fix: bulk del cache keys

pull/7464/head
mertmit 10 months ago
parent
commit
ae84a51b5c
  1. 2
      packages/nocodb/src/cache/NocoCache.ts
  2. 11
      packages/nocodb/src/cache/RedisCacheMgr.ts
  3. 11
      packages/nocodb/src/cache/RedisMockCacheMgr.ts
  4. 22
      packages/nocodb/src/models/View.ts

2
packages/nocodb/src/cache/NocoCache.ts vendored

@ -54,6 +54,8 @@ export default class NocoCache {
public static async del(key): Promise<boolean> {
if (this.cacheDisabled) return Promise.resolve(true);
if (Array.isArray(key))
return this.client.del(key.map((k) => `${this.prefix}:${k}`));
return this.client.del(`${this.prefix}:${key}`);
}

11
packages/nocodb/src/cache/RedisCacheMgr.ts vendored

@ -44,7 +44,13 @@ export default class RedisCacheMgr extends CacheMgr {
// @ts-ignore
async del(key: string[] | string): Promise<any> {
log(`RedisCacheMgr::del: deleting key ${key}`);
return this.client.del(Array.isArray(key) ? key : [key]);
if (Array.isArray(key)) {
if (key.length) {
return this.client.del(key);
}
} else if (key) {
return this.client.del(key);
}
}
// @ts-ignore
@ -223,7 +229,6 @@ export default class RedisCacheMgr extends CacheMgr {
if (list.length) {
// set target list
log(`RedisCacheMgr::deepDel: set key ${listKey}`);
await this.del(listKey);
await this.set(listKey, list);
}
}
@ -234,7 +239,7 @@ export default class RedisCacheMgr extends CacheMgr {
// given a list key, delete all the children
const listOfChildren = await this.get(key, CacheGetType.TYPE_ARRAY);
// delete each child key
await Promise.all(listOfChildren.map(async (k) => await this.del(k)));
await this.del(listOfChildren);
// delete list key
return await this.del(key);
} else {

11
packages/nocodb/src/cache/RedisMockCacheMgr.ts vendored

@ -37,7 +37,13 @@ export default class RedisMockCacheMgr extends CacheMgr {
// @ts-ignore
async del(key: string[] | string): Promise<any> {
log(`RedisMockCacheMgr::del: deleting key ${key}`);
return this.client.del(Array.isArray(key) ? key : [key]);
if (Array.isArray(key)) {
if (key.length) {
return this.client.del(key);
}
} else if (key) {
return this.client.del(key);
}
}
// @ts-ignore
@ -220,7 +226,6 @@ export default class RedisMockCacheMgr extends CacheMgr {
if (list.length) {
// set target list
log(`RedisMockCacheMgr::deepDel: set key ${listKey}`);
await this.del(listKey);
await this.set(listKey, list);
}
}
@ -231,7 +236,7 @@ export default class RedisMockCacheMgr extends CacheMgr {
// given a list key, delete all the children
const listOfChildren = await this.get(key, CacheGetType.TYPE_ARRAY);
// delete each child key
await Promise.all(listOfChildren.map(async (k) => await this.del(k)));
await this.del(listOfChildren);
// delete list key
return await this.del(key);
} else {

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

@ -1520,24 +1520,20 @@ export default class View implements ViewType {
});
}
// clear cache for each view
await Promise.all([
...viewsList.map(async (view) => {
await NocoCache.del(
const deleteKeys = [];
for (const view of viewsList) {
deleteKeys.push(
`${CacheScope.SINGLE_QUERY}:${modelId}:${view.id}:queries`,
);
await NocoCache.del(
`${CacheScope.SINGLE_QUERY}:${modelId}:${view.id}:read`,
);
}),
(async () => {
await NocoCache.del(
}
deleteKeys.push(
`${CacheScope.SINGLE_QUERY}:${modelId}:default:queries`,
);
await NocoCache.del(
`${CacheScope.SINGLE_QUERY}:${modelId}:default:read`,
);
})(),
]);
await NocoCache.del(deleteKeys);
}
}

Loading…
Cancel
Save