From e3a06191e37f87a25eeddca0bc25d3212d7e1240 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 31 May 2023 13:24:51 +0800 Subject: [PATCH] fix(nocodb): revise user project list delete logic --- packages/nocodb/src/models/ProjectUser.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/nocodb/src/models/ProjectUser.ts b/packages/nocodb/src/models/ProjectUser.ts index f3d8897541..31eda80fbb 100644 --- a/packages/nocodb/src/models/ProjectUser.ts +++ b/packages/nocodb/src/models/ProjectUser.ts @@ -194,11 +194,16 @@ export default class ProjectUser { const { isNoneList } = cachedList; if (!isNoneList && cachedProjectList?.length) { cachedProjectList = cachedProjectList.filter((p) => p.id !== projectId); - await NocoCache.setList( - CacheScope.USER_PROJECT, - [userId], - cachedProjectList, - ); + // delete the whole list first so that the old one won't be included + await NocoCache.del(`${CacheScope.USER_PROJECT}:${userId}:list`); + if (cachedProjectList.length > 0) { + // set the updated list (i.e. excluding the to-be-deleted project id) + await NocoCache.setList( + CacheScope.USER_PROJECT, + [userId], + cachedProjectList, + ); + } } await NocoCache.del(`${CacheScope.PROJECT_USER}:${projectId}:${userId}`);