Browse Source

feat: allow custom prefix for setList

pull/7202/head
mertmit 12 months ago
parent
commit
f8f2fd6e1d
  1. 1
      packages/nocodb/src/cache/CacheMgr.ts
  2. 3
      packages/nocodb/src/cache/NocoCache.ts
  3. 10
      packages/nocodb/src/cache/RedisCacheMgr.ts
  4. 10
      packages/nocodb/src/cache/RedisMockCacheMgr.ts

1
packages/nocodb/src/cache/CacheMgr.ts vendored

@ -21,6 +21,7 @@ export default abstract class CacheMgr {
scope: string, scope: string,
subListKeys: string[], subListKeys: string[],
list: any[], list: any[],
props?: string[],
): Promise<boolean>; ): Promise<boolean>;
public abstract deepDel( public abstract deepDel(
scope: string, scope: string,

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

@ -86,9 +86,10 @@ export default class NocoCache {
scope: string, scope: string,
subListKeys: string[], subListKeys: string[],
list: any[], list: any[],
props: string[] = [],
): Promise<boolean> { ): Promise<boolean> {
if (this.cacheDisabled) return Promise.resolve(true); if (this.cacheDisabled) return Promise.resolve(true);
return this.client.setList(scope, subListKeys, list); return this.client.setList(scope, subListKeys, list, props);
} }
public static async deepDel( public static async deepDel(

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

@ -185,6 +185,7 @@ export default class RedisCacheMgr extends CacheMgr {
scope: string, scope: string,
subListKeys: string[], subListKeys: string[],
list: any[], list: any[],
props: string[] = [],
): Promise<boolean> { ): Promise<boolean> {
// remove null from arrays // remove null from arrays
subListKeys = subListKeys.filter((k) => k); subListKeys = subListKeys.filter((k) => k);
@ -203,12 +204,19 @@ export default class RedisCacheMgr extends CacheMgr {
(await this.get(listKey, CacheGetType.TYPE_ARRAY)) || []; (await this.get(listKey, CacheGetType.TYPE_ARRAY)) || [];
for (const o of list) { for (const o of list) {
// construct key for Get // construct key for Get
// e.g. nc:<orgs>:<scope>:<model_id_1>
let getKey = `${this.prefix}:${scope}:${o.id}`; let getKey = `${this.prefix}:${scope}:${o.id}`;
if (props.length) {
const propValues = props.map((p) => o[p]);
// e.g. nc:<orgs>:<scope>:<prop_value_1>:<prop_value_2>
getKey = `${this.prefix}:${scope}:${propValues.join(':')}`;
} else {
// e.g. nc:<orgs>:<scope>:<model_id_1>
getKey = `${this.prefix}:${scope}:${o.id}`;
// special case - MODEL_ROLE_VISIBILITY // special case - MODEL_ROLE_VISIBILITY
if (scope === CacheScope.MODEL_ROLE_VISIBILITY) { if (scope === CacheScope.MODEL_ROLE_VISIBILITY) {
getKey = `${this.prefix}:${scope}:${o.fk_view_id}:${o.role}`; getKey = `${this.prefix}:${scope}:${o.fk_view_id}:${o.role}`;
} }
}
// set Get Key // set Get Key
log(`RedisCacheMgr::setList: setting key ${getKey}`); log(`RedisCacheMgr::setList: setting key ${getKey}`);
await this.set(getKey, JSON.stringify(o, this.getCircularReplacer())); await this.set(getKey, JSON.stringify(o, this.getCircularReplacer()));

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

@ -185,6 +185,7 @@ export default class RedisMockCacheMgr extends CacheMgr {
scope: string, scope: string,
subListKeys: string[], subListKeys: string[],
list: any[], list: any[],
props: string[] = [],
): Promise<boolean> { ): Promise<boolean> {
// remove null from arrays // remove null from arrays
subListKeys = subListKeys.filter((k) => k); subListKeys = subListKeys.filter((k) => k);
@ -203,12 +204,19 @@ export default class RedisMockCacheMgr extends CacheMgr {
(await this.get(listKey, CacheGetType.TYPE_ARRAY)) || []; (await this.get(listKey, CacheGetType.TYPE_ARRAY)) || [];
for (const o of list) { for (const o of list) {
// construct key for Get // construct key for Get
// e.g. nc:<orgs>:<scope>:<model_id_1>
let getKey = `${this.prefix}:${scope}:${o.id}`; let getKey = `${this.prefix}:${scope}:${o.id}`;
if (props.length) {
const propValues = props.map((p) => o[p]);
// e.g. nc:<orgs>:<scope>:<prop_value_1>:<prop_value_2>
getKey = `${this.prefix}:${scope}:${propValues.join(':')}`;
} else {
// e.g. nc:<orgs>:<scope>:<model_id_1>
getKey = `${this.prefix}:${scope}:${o.id}`;
// special case - MODEL_ROLE_VISIBILITY // special case - MODEL_ROLE_VISIBILITY
if (scope === CacheScope.MODEL_ROLE_VISIBILITY) { if (scope === CacheScope.MODEL_ROLE_VISIBILITY) {
getKey = `${this.prefix}:${scope}:${o.fk_view_id}:${o.role}`; getKey = `${this.prefix}:${scope}:${o.fk_view_id}:${o.role}`;
} }
}
// set Get Key // set Get Key
log(`RedisMockCacheMgr::setList: setting key ${getKey}`); log(`RedisMockCacheMgr::setList: setting key ${getKey}`);
await this.set(getKey, JSON.stringify(o, this.getCircularReplacer())); await this.set(getKey, JSON.stringify(o, this.getCircularReplacer()));

Loading…
Cancel
Save