diff --git a/CHANGELOG.md b/CHANGELOG.md index d3c7677a..27bcb0de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +2.1.6-SNAPSHOT / WIP +================== +Improvements: +* [OLMIS-7954](https://openlmis.atlassian.net/browse/OLMIS-7954): Added fixes to improve performance on login page + 2.1.5 / 2023-06-26 ================== Bug fixes: diff --git a/src/stock-adjustment-creation/source-destination.service.js b/src/stock-adjustment-creation/source-destination.service.js index 104b8dd5..667b3f7c 100644 --- a/src/stock-adjustment-creation/source-destination.service.js +++ b/src/stock-adjustment-creation/source-destination.service.js @@ -41,19 +41,19 @@ this.clearSourcesCache = clearSourcesCache; this.clearDestinationsCache = clearDestinationsCache; - function getSourceAssignments(programId, facilityId) { + function getSourceAssignments(programIds, facilityId) { var resource = $resource(stockmanagementUrlFactory('/api/validSources')); if (offlineService.isOffline()) { var sources = offlineSources.search({ - programId: programId, + programId: programIds, facilityId: facilityId }); return checkArrayAndGetData(sources); } return resource.get({ - programId: programId, + programId: programIds, facilityId: facilityId, page: 0, size: 2147483647 @@ -63,19 +63,19 @@ }); } - function getDestinationAssignments(programId, facilityId) { + function getDestinationAssignments(programIds, facilityId) { var resource = $resource(stockmanagementUrlFactory('/api/validDestinations')); if (offlineService.isOffline()) { var destinations = offlineDestinations.search({ - programId: programId, + programId: programIds, facilityId: facilityId }); return checkArrayAndGetData(destinations); } return resource.get({ - programId: programId, + programId: programIds, facilityId: facilityId, page: 0, size: 2147483647 diff --git a/src/stock-reason/stock-reason-cache.run.js b/src/stock-reason/stock-reason-cache.run.js index 56f171ee..74622a5a 100644 --- a/src/stock-reason/stock-reason-cache.run.js +++ b/src/stock-reason/stock-reason-cache.run.js @@ -27,19 +27,20 @@ loginService.registerPostLoginAction(function() { stockReasonsFactory.clearReasonsCache(); - var homeFacility, - reasons = []; + var homeFacility; return facilityFactory.getUserHomeFacility() .then(function(facility) { homeFacility = facility; var programs = homeFacility.supportedPrograms; - programs.forEach(function(program) { - reasons.push(stockReasonsFactory.getReasons( - program.id ? program.id : program, - homeFacility.type ? homeFacility.type.id : homeFacility - )); + var supportedProgramsIds = programs.map(function(program) { + return program.id ? program.id : program; }); + + return stockReasonsFactory.getReasons( + supportedProgramsIds, + homeFacility.type ? homeFacility.type.id : homeFacility + ); }) .catch(function() { return $q.resolve(); diff --git a/src/stock-reason/stock-reasons.factory.js b/src/stock-reason/stock-reasons.factory.js index 5264598d..99f8c424 100644 --- a/src/stock-reason/stock-reasons.factory.js +++ b/src/stock-reason/stock-reasons.factory.js @@ -143,8 +143,8 @@ * @param {Object} reasonType the reason type, can be an array * @return {Promise} the promise resolving to the list of reasons */ - function getReasons(program, facilityType, reasonType) { - return $q.resolve(getReasonsPromise(program, facilityType, reasonType) + function getReasons(programIds, facilityType, reasonType) { + return $q.resolve(getReasonsPromise(programIds, facilityType, reasonType) .then(function(reasonAssignments) { return reasonAssignments .filter(function(reasonAssignment) { @@ -155,17 +155,17 @@ result.push(reasonAssignment.reason); } if (!offlineService.isOffline()) { - cacheReasons(reasonAssignment, program, facilityType); + cacheReasons(reasonAssignment, programIds, facilityType); } return result; }, []); })); } - function getReasonsPromise(program, facilityType, reasonType) { + function getReasonsPromise(programIds, facilityType, reasonType) { if (offlineService.isOffline()) { var reasons = offlineReasons.search({ - programId: program, + programId: programIds, reasonType: reasonType, facilityType: facilityType }); @@ -177,17 +177,17 @@ return $q.resolve(reasons); } return new ValidReasonResource().query({ - program: program, + program: programIds, facilityType: facilityType, reasonType: reasonType }); } - function cacheReasons(reasonAssignment, programId, facilityType) { + function cacheReasons(reasonAssignment, programIds, facilityType) { var reason = angular.copy(reasonAssignment.reason); var reasonToCache = { id: reasonAssignment.id, - programId: programId, + programId: programIds, facilityType: facilityType, reasonType: reason.reasonType, reason: reason, diff --git a/src/stock-valid-destinations/destination-cache.run.js b/src/stock-valid-destinations/destination-cache.run.js index 32921f49..c3a8b243 100644 --- a/src/stock-valid-destinations/destination-cache.run.js +++ b/src/stock-valid-destinations/destination-cache.run.js @@ -27,19 +27,22 @@ loginService.registerPostLoginAction(function() { sourceDestinationService.clearDestinationsCache(); - var homeFacility, - destinations = []; + var homeFacility; return facilityFactory.getUserHomeFacility() .then(function(facility) { homeFacility = facility; var programs = homeFacility.supportedPrograms; - programs.forEach(function(program) { - destinations.push(sourceDestinationService.getDestinationAssignments( - program.id ? program.id : program, - homeFacility.id ? homeFacility.id : homeFacility - )); + var supportedProgramsIds = programs.map(function(program) { + return program.id ? program.id : program; }); + + var destinations = sourceDestinationService.getDestinationAssignments( + supportedProgramsIds, + homeFacility.id ? homeFacility.id : homeFacility + ); + + return destinations; }) .catch(function() { return $q.resolve(); diff --git a/src/stock-valid-sources/source-cache.run.js b/src/stock-valid-sources/source-cache.run.js index d2414298..f873ccfc 100644 --- a/src/stock-valid-sources/source-cache.run.js +++ b/src/stock-valid-sources/source-cache.run.js @@ -27,19 +27,22 @@ loginService.registerPostLoginAction(function() { sourceDestinationService.clearSourcesCache(); - var homeFacility, - sources = []; + var homeFacility; return facilityFactory.getUserHomeFacility() .then(function(facility) { homeFacility = facility; var programs = homeFacility.supportedPrograms; - programs.forEach(function(program) { - sources.push(sourceDestinationService.getSourceAssignments( - program.id ? program.id : program, - homeFacility.id ? homeFacility.id : homeFacility - )); + var supportedProgramsIds = programs.map(function(program) { + return program.id ? program.id : program; }); + + var sources = sourceDestinationService.getSourceAssignments( + supportedProgramsIds, + homeFacility.id ? homeFacility.id : homeFacility + ); + + return sources; }) .catch(function() { return $q.resolve();