From 01cb388e6c5fadc3d4a47b03a26860fdc40e20bf Mon Sep 17 00:00:00 2001 From: Prateek Shourya Date: Thu, 5 Dec 2024 13:42:07 +0530 Subject: [PATCH] improvement: update fetch map during workspace-level module fetch to reduce redundant API calls --- web/core/store/module.store.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web/core/store/module.store.ts b/web/core/store/module.store.ts index f7a99a5c431..23f2af67205 100644 --- a/web/core/store/module.store.ts +++ b/web/core/store/module.store.ts @@ -39,7 +39,7 @@ export interface IModuleStore { updateModuleDistribution: (distributionUpdates: DistributionUpdates, moduleId: string) => void; fetchWorkspaceModules: (workspaceSlug: string) => Promise; fetchModules: (workspaceSlug: string, projectId: string) => Promise; - fetchModulesSlim: (workspaceSlug: string, projectId: string) => Promise + fetchModulesSlim: (workspaceSlug: string, projectId: string) => Promise; fetchArchivedModules: (workspaceSlug: string, projectId: string) => Promise; fetchArchivedModuleDetails: (workspaceSlug: string, projectId: string, moduleId: string) => Promise; fetchModuleDetails: (workspaceSlug: string, projectId: string, moduleId: string) => Promise; @@ -253,6 +253,11 @@ export class ModulesStore implements IModuleStore { response.forEach((module) => { set(this.moduleMap, [module.id], { ...this.moduleMap[module.id], ...module }); }); + // check for all unique project ids and update the fetchedMap + const uniqueProjectIds = new Set(response.map((module) => module.project_id)); + uniqueProjectIds.forEach((projectId) => { + set(this.fetchedMap, projectId, true); + }); }); return response; });