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

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

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

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

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

Loading…
Cancel
Save