fix: reduce the number of db calls for getSessionUser (#37385)

* Fix: Reduce the number of db calls for getSessionUser

* Fix unit tests
This commit is contained in:
Stuart Taylor
2019-10-18 01:17:37 +01:00
committed by mrugesh
parent 3a2db6f090
commit 892e6862ed
4 changed files with 22 additions and 11 deletions

View File

@ -110,9 +110,7 @@ export function getUserById(id, User = loopback.getModelByType('User')) {
if (err || isEmpty(instance)) {
return reject(err || 'No user instance found');
}
instance.points =
(instance.progressTimestamps && instance.progressTimestamps.length) ||
1;
let completedChallengeCount = 0;
let completedProjectCount = 0;
if ('completedChallenges' in instance) {
@ -126,12 +124,14 @@ export function getUserById(id, User = loopback.getModelByType('User')) {
}
});
}
instance.completedChallengeCount = completedChallengeCount;
instance.completedProjectCount = completedProjectCount;
instance.completedCertCount = getCompletedCertCount(instance);
instance.completedLegacyCertCount = getLegacyCertCount(instance);
instance.completedChallenges = [];
delete instance.progressTimestamps;
instance.points =
(instance.progressTimestamps && instance.progressTimestamps.length) ||
1;
return resolve(instance);
})
);