improvement: update fetch map during workspace-level module fetch to reduce redundant API calls (#6159)

This commit is contained in:
Prateek Shourya
2024-12-05 15:26:15 +05:30
committed by GitHub
parent 6cd8af1092
commit aa1e192a50
+6 -1
View File
@@ -39,7 +39,7 @@ export interface IModuleStore {
updateModuleDistribution: (distributionUpdates: DistributionUpdates, moduleId: string) => void;
fetchWorkspaceModules: (workspaceSlug: string) => Promise<IModule[]>;
fetchModules: (workspaceSlug: string, projectId: string) => Promise<undefined | IModule[]>;
fetchModulesSlim: (workspaceSlug: string, projectId: string) => Promise<undefined | IModule[]>
fetchModulesSlim: (workspaceSlug: string, projectId: string) => Promise<undefined | IModule[]>;
fetchArchivedModules: (workspaceSlug: string, projectId: string) => Promise<undefined | IModule[]>;
fetchArchivedModuleDetails: (workspaceSlug: string, projectId: string, moduleId: string) => Promise<IModule>;
fetchModuleDetails: (workspaceSlug: string, projectId: string, moduleId: string) => Promise<IModule>;
@@ -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;
});