Browse Source

feat: allow custom prefix for setList

pull/7202/head
mertmit 11 months ago
parent
commit
f8f2fd6e1d
  1. 1
      packages/nocodb/src/cache/CacheMgr.ts
  2. 3
      packages/nocodb/src/cache/NocoCache.ts
  3. 16
      packages/nocodb/src/cache/RedisCacheMgr.ts
  4. 16
      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,
subListKeys: string[],
list: any[],
props?: string[],
): Promise<boolean>;
public abstract deepDel(
scope: string,

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

@ -86,9 +86,10 @@ export default class NocoCache {
scope: string,
subListKeys: string[],
list: any[],
props: string[] = [],
): Promise<boolean> {
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(

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

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

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

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

Loading…
Cancel
Save