From 4b9b0dbbb9de4c35479d88958925c6fc7ce3e880 Mon Sep 17 00:00:00 2001 From: Archer <545436317@qq.com> Date: Wed, 11 Dec 2024 22:12:57 +0800 Subject: [PATCH] perf: private app check (#3376) * perf: private app check * perf: clb count --- projects/app/src/pages/api/core/app/list.ts | 38 ++++++++++--------- .../app/src/pages/api/core/dataset/list.ts | 34 +++++++++-------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/projects/app/src/pages/api/core/app/list.ts b/projects/app/src/pages/api/core/app/list.ts index 34c36dd65..7f3f5ce13 100644 --- a/projects/app/src/pages/api/core/app/list.ts +++ b/projects/app/src/pages/api/core/app/list.ts @@ -157,26 +157,30 @@ async function handler(req: ApiRequestProps): Promise item.permission) ); - // Count app collaborators - const clbCount = perList.filter( - (item) => String(item.resourceId) === String(app._id) - ).length; - - return { - Per: new AppPermission({ - per: tmbPer ?? groupPer ?? AppDefaultPermissionVal, - isOwner: String(app.tmbId) === String(tmbId) || teamPer.isOwner - }), - privateApp: AppFolderTypeList.includes(app.type) ? clbCount <= 1 : clbCount === 0 - }; + return new AppPermission({ + per: tmbPer ?? groupPer ?? AppDefaultPermissionVal, + isOwner: String(app.tmbId) === String(tmbId) || teamPer.isOwner + }); }; - // Inherit app - if (app.inheritPermission && app.parentId && !AppFolderTypeList.includes(app.type)) { - return getPer(String(app.parentId)); - } else { - return getPer(String(app._id)); + const getClbCount = (appId: string) => { + return perList.filter((item) => String(item.resourceId) === String(appId)).length; + }; + + // Inherit app, check parent folder clb + if (!AppFolderTypeList.includes(app.type) && app.parentId && app.inheritPermission) { + return { + Per: getPer(String(app.parentId)), + privateApp: getClbCount(String(app.parentId)) <= 1 + }; } + + return { + Per: getPer(String(app._id)), + privateApp: AppFolderTypeList.includes(app.type) + ? getClbCount(String(app._id)) <= 1 + : getClbCount(String(app._id)) === 0 + }; })(); return { diff --git a/projects/app/src/pages/api/core/dataset/list.ts b/projects/app/src/pages/api/core/dataset/list.ts index d8674bed5..6e404e011 100644 --- a/projects/app/src/pages/api/core/dataset/list.ts +++ b/projects/app/src/pages/api/core/dataset/list.ts @@ -127,29 +127,33 @@ async function handler(req: ApiRequestProps) { .filter((item) => String(item.resourceId) === datasetId && !!item.groupId) .map((item) => item.permission) ); - - const clbCount = perList.filter( - (item) => String(item.resourceId) === String(dataset._id) - ).length; - - return { - Per: new DatasetPermission({ - per: tmbPer ?? groupPer ?? DatasetDefaultPermissionVal, - isOwner: String(dataset.tmbId) === String(tmbId) || teamPer.isOwner - }), - privateDataset: dataset.type === 'folder' ? clbCount <= 1 : clbCount === 0 - }; + return new DatasetPermission({ + per: tmbPer ?? groupPer ?? DatasetDefaultPermissionVal, + isOwner: String(dataset.tmbId) === String(tmbId) || teamPer.isOwner + }); }; + const getClbCount = (datasetId: string) => { + return perList.filter((item) => String(item.resourceId) === String(datasetId)).length; + }; + // inherit if ( dataset.inheritPermission && dataset.parentId && dataset.type !== DatasetTypeEnum.folder ) { - return getPer(String(dataset.parentId)); - } else { - return getPer(String(dataset._id)); + return { + Per: getPer(String(dataset.parentId)), + privateDataset: getClbCount(String(dataset.parentId)) <= 1 + }; } + return { + Per: getPer(String(dataset._id)), + privateDataset: + dataset.type === DatasetTypeEnum.folder + ? getClbCount(String(dataset._id)) <= 1 + : getClbCount(String(dataset._id)) === 0 + }; })(); return {