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:
@ -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);
|
||||
})
|
||||
);
|
||||
|
Reference in New Issue
Block a user