From 8bfcacca5cc04c16977dd276947a8ac047cdae1e Mon Sep 17 00:00:00 2001 From: mertmit Date: Fri, 26 Jan 2024 08:13:37 +0000 Subject: [PATCH] fix: fallback for missing list key --- packages/nocodb/src/cache/RedisCacheMgr.ts | 22 +++++++++++++++++ .../nocodb/src/cache/RedisMockCacheMgr.ts | 24 ++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/packages/nocodb/src/cache/RedisCacheMgr.ts b/packages/nocodb/src/cache/RedisCacheMgr.ts index 882eaedb9e..5777cbe664 100644 --- a/packages/nocodb/src/cache/RedisCacheMgr.ts +++ b/packages/nocodb/src/cache/RedisCacheMgr.ts @@ -169,6 +169,28 @@ export default class RedisCacheMgr extends CacheMgr { log(`RedisCacheMgr::getList: getting list with keys ${arr}`); const values = await this.client.mget(arr); + if (values.some((v) => v === null)) { + // FALLBACK: a key is missing from list, this should never happen + console.error(`RedisCacheMgr::getList: missing value for ${key}`); + const allParents = []; + // get all parents from children + values.forEach((v) => { + allParents.push(...this.getParents(v)); + }); + // remove duplicates + const uniqueParents = [...new Set(allParents)]; + // delete all parents and children + await Promise.all( + uniqueParents.map(async (p) => { + await this.deepDel(scope, p, CacheDelDirection.PARENT_TO_CHILD); + }), + ); + return Promise.resolve({ + list: [], + isNoneList, + }); + } + return { list: values.map((res) => { try { diff --git a/packages/nocodb/src/cache/RedisMockCacheMgr.ts b/packages/nocodb/src/cache/RedisMockCacheMgr.ts index 47b0926229..1a098646be 100644 --- a/packages/nocodb/src/cache/RedisMockCacheMgr.ts +++ b/packages/nocodb/src/cache/RedisMockCacheMgr.ts @@ -163,9 +163,31 @@ export default class RedisMockCacheMgr extends CacheMgr { }); } - log(`RedisCacheMgr::getList: getting list with keys ${arr}`); + log(`RedisMockCacheMgr::getList: getting list with keys ${arr}`); const values = await this.client.mget(arr); + if (values.some((v) => v === null)) { + // FALLBACK: a key is missing from list, this should never happen + console.error(`RedisMockCacheMgr::getList: missing value for ${key}`); + const allParents = []; + // get all parents from children + values.forEach((v) => { + allParents.push(...this.getParents(v)); + }); + // remove duplicates + const uniqueParents = [...new Set(allParents)]; + // delete all parents and children + await Promise.all( + uniqueParents.map(async (p) => { + await this.deepDel(scope, p, CacheDelDirection.PARENT_TO_CHILD); + }), + ); + return Promise.resolve({ + list: [], + isNoneList, + }); + } + return { list: values.map((res) => { try {