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

@ -983,6 +983,12 @@ export default function(User) {
});
User.prototype.getPoints$ = function getPoints$() {
if (
Array.isArray(this.progressTimestamps) &&
this.progressTimestamps.length
) {
return Observable.of(this.progressTimestamps);
}
const id = this.getId();
const filter = {
where: { id },
@ -994,6 +1000,12 @@ export default function(User) {
});
};
User.prototype.getCompletedChallenges$ = function getCompletedChallenges$() {
if (
Array.isArray(this.completedChallenges) &&
this.completedChallenges.length
) {
return Observable.of(this.completedChallenges);
}
const id = this.getId();
const filter = {
where: { id },