Skip to content

Commit

Permalink
OLMIS-7954: Added fixes to improve performance on login page
Browse files Browse the repository at this point in the history
  • Loading branch information
jdolkowski committed Jul 4, 2024
1 parent 6c67c08 commit af65a20
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 35 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
12 changes: 6 additions & 6 deletions src/stock-adjustment-creation/source-destination.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions src/stock-reason/stock-reason-cache.run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions src/stock-reason/stock-reasons.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
});
Expand All @@ -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,
Expand Down
17 changes: 10 additions & 7 deletions src/stock-valid-destinations/destination-cache.run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 10 additions & 7 deletions src/stock-valid-sources/source-cache.run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit af65a20

Please sign in to comment.