|
|
@ -114,7 +114,13 @@ export default class RedisMockCacheMgr extends CacheMgr { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async getList(scope: string, subKeys: string[]): Promise<any[]> { |
|
|
|
async getList( |
|
|
|
|
|
|
|
scope: string, |
|
|
|
|
|
|
|
subKeys: string[], |
|
|
|
|
|
|
|
): Promise<{ |
|
|
|
|
|
|
|
list: any[]; |
|
|
|
|
|
|
|
isNoneList: boolean; |
|
|
|
|
|
|
|
}> { |
|
|
|
// remove null from arrays
|
|
|
|
// remove null from arrays
|
|
|
|
subKeys = subKeys.filter((k) => k); |
|
|
|
subKeys = subKeys.filter((k) => k); |
|
|
|
// e.g. key = nc:<orgs>:<scope>:<project_id_1>:<base_id_1>:list
|
|
|
|
// e.g. key = nc:<orgs>:<scope>:<project_id_1>:<base_id_1>:list
|
|
|
@ -125,9 +131,21 @@ export default class RedisMockCacheMgr extends CacheMgr { |
|
|
|
// e.g. arr = ["nc:<orgs>:<scope>:<model_id_1>", "nc:<orgs>:<scope>:<model_id_2>"]
|
|
|
|
// e.g. arr = ["nc:<orgs>:<scope>:<model_id_1>", "nc:<orgs>:<scope>:<model_id_2>"]
|
|
|
|
const arr = (await this.get(key, CacheGetType.TYPE_ARRAY)) || []; |
|
|
|
const arr = (await this.get(key, CacheGetType.TYPE_ARRAY)) || []; |
|
|
|
log(`RedisMockCacheMgr::getList: getting list with key ${key}`); |
|
|
|
log(`RedisMockCacheMgr::getList: getting list with key ${key}`); |
|
|
|
return Promise.all( |
|
|
|
const isNoneList = arr.length && arr[0] === 'NONE'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isNoneList) { |
|
|
|
|
|
|
|
return Promise.resolve({ |
|
|
|
|
|
|
|
list: [], |
|
|
|
|
|
|
|
isNoneList, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
list: await Promise.all( |
|
|
|
arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)), |
|
|
|
arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)), |
|
|
|
); |
|
|
|
), |
|
|
|
|
|
|
|
isNoneList, |
|
|
|
|
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async setList( |
|
|
|
async setList( |
|
|
@ -144,10 +162,8 @@ export default class RedisMockCacheMgr extends CacheMgr { |
|
|
|
? `${this.prefix}:${scope}:list` |
|
|
|
? `${this.prefix}:${scope}:list` |
|
|
|
: `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; |
|
|
|
: `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; |
|
|
|
if (!list.length) { |
|
|
|
if (!list.length) { |
|
|
|
log( |
|
|
|
// Set NONE here so that it won't hit the DB on each page load
|
|
|
|
`RedisMockCacheMgr::setList: List is empty for ${listKey}. Skipping ...`, |
|
|
|
return this.set(listKey, ['NONE']); |
|
|
|
); |
|
|
|
|
|
|
|
return Promise.resolve(true); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// fetch existing list
|
|
|
|
// fetch existing list
|
|
|
|
const listOfGetKeys = |
|
|
|
const listOfGetKeys = |
|
|
@ -227,7 +243,11 @@ export default class RedisMockCacheMgr extends CacheMgr { |
|
|
|
? `${this.prefix}:${scope}:list` |
|
|
|
? `${this.prefix}:${scope}:list` |
|
|
|
: `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; |
|
|
|
: `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; |
|
|
|
log(`RedisMockCacheMgr::appendToList: append key ${key} to ${listKey}`); |
|
|
|
log(`RedisMockCacheMgr::appendToList: append key ${key} to ${listKey}`); |
|
|
|
const list = (await this.get(listKey, CacheGetType.TYPE_ARRAY)) || []; |
|
|
|
let list = (await this.get(listKey, CacheGetType.TYPE_ARRAY)) || []; |
|
|
|
|
|
|
|
if (list.length && list[0] === 'NONE') { |
|
|
|
|
|
|
|
list = []; |
|
|
|
|
|
|
|
await this.del(listKey); |
|
|
|
|
|
|
|
} |
|
|
|
list.push(key); |
|
|
|
list.push(key); |
|
|
|
return this.set(listKey, list); |
|
|
|
return this.set(listKey, list); |
|
|
|
} |
|
|
|
} |
|
|
|