diff --git a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts index b8deaae118..b8a457c3c9 100644 --- a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts @@ -44,7 +44,7 @@ export default class RedisCacheMgr extends CacheMgr { async get(key: string, type: string, config?: any): Promise { log(`RedisCacheMgr::get: getting key ${key} with type ${type}`); if (type === CacheGetType.TYPE_ARRAY) { - return this.client.smembers(key); + return await this.client.smembers(key); } else if (type === CacheGetType.TYPE_OBJECT) { const res = await this.client.get(key); try { @@ -114,7 +114,13 @@ export default class RedisCacheMgr extends CacheMgr { ); } - async getList(scope: string, subKeys: string[]): Promise { + async getList( + scope: string, + subKeys: string[] + ): Promise<{ + list: any[]; + isEmptyList: boolean; + }> { // remove null from arrays subKeys = subKeys.filter((k) => k); // e.g. key = nc:::::list @@ -125,9 +131,17 @@ export default class RedisCacheMgr extends CacheMgr { // e.g. arr = ["nc:::", "nc:::"] const arr = (await this.get(key, CacheGetType.TYPE_ARRAY)) || []; log(`RedisCacheMgr::getList: getting list with key ${key}`); - return Promise.all( - arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) - ); + let list: any[] = []; + const isEmptyList = arr[0] === 'NONE'; + if (!isEmptyList) { + list = await Promise.all( + arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) + ); + } + return { + list, + isEmptyList, + }; } async setList( @@ -144,8 +158,7 @@ export default class RedisCacheMgr extends CacheMgr { ? `${this.prefix}:${scope}:list` : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; if (!list.length) { - log(`RedisCacheMgr::setList: List is empty for ${listKey}. Skipping ...`); - return Promise.resolve(true); + return this.set(listKey, ['NONE']); } // fetch existing list const listOfGetKeys = diff --git a/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts index a06ddd9fe5..53d084abab 100644 --- a/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts @@ -43,7 +43,7 @@ export default class RedisMockCacheMgr extends CacheMgr { async get(key: string, type: string, config?: any): Promise { log(`RedisMockCacheMgr::get: getting key ${key} with type ${type}`); if (type === CacheGetType.TYPE_ARRAY) { - return this.client.smembers(key); + return await this.client.smembers(key); } else if (type === CacheGetType.TYPE_OBJECT) { const res = await this.client.get(key); try { @@ -114,7 +114,13 @@ export default class RedisMockCacheMgr extends CacheMgr { ); } - async getList(scope: string, subKeys: string[]): Promise { + async getList( + scope: string, + subKeys: string[] + ): Promise<{ + list: any[]; + isEmptyList: boolean; + }> { // remove null from arrays subKeys = subKeys.filter((k) => k); // e.g. key = nc:::::list @@ -125,9 +131,17 @@ export default class RedisMockCacheMgr extends CacheMgr { // e.g. arr = ["nc:::", "nc:::"] const arr = (await this.get(key, CacheGetType.TYPE_ARRAY)) || []; log(`RedisMockCacheMgr::getList: getting list with key ${key}`); - return Promise.all( - arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) - ); + let list: any[] = []; + const isEmptyList = arr[0] === 'NONE'; + if (!isEmptyList) { + list = await Promise.all( + arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) + ); + } + return { + list, + isEmptyList, + }; } async setList( @@ -144,10 +158,7 @@ export default class RedisMockCacheMgr extends CacheMgr { ? `${this.prefix}:${scope}:list` : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; if (!list.length) { - log( - `RedisMockCacheMgr::setList: List is empty for ${listKey}. Skipping ...` - ); - return Promise.resolve(true); + return this.set(listKey, ['NONE']); } // fetch existing list const listOfGetKeys =