From 5d2ef0fadf531aa8eaddb39ac7f526a64e06d8f3 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Fri, 6 Dec 2019 18:07:55 -0500 Subject: [PATCH] [U] Cache numericGrade --- src/logic/course.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/logic/course.ts b/src/logic/course.ts index 6a3a102..ff9e085 100644 --- a/src/logic/course.ts +++ b/src/logic/course.ts @@ -193,29 +193,24 @@ export default class Course }) } - private _cacheNumericGrade: number; - /** * Get numeric grade */ get numericGrade(): number { - // Cached - if (this._cacheNumericGrade == null) + return this.cache.get('NumericGrade', () => { // Calculate if (this.grading.method == 'PERCENT_TYPE') { - this._cacheNumericGrade = GPAUtils.getPercentTypeAverage(this, this.assignments); + return GPAUtils.getPercentTypeAverage(this, this.assignments); } else if (this.grading.method == 'TOTAL_MEAN') { - this._cacheNumericGrade = GPAUtils.getTotalMeanAverage(this.assignments); + return GPAUtils.getTotalMeanAverage(this.assignments); } - else this._cacheNumericGrade = -1; - } - - return this._cacheNumericGrade; + else return -1; + }) } private _cacheAssignmentTypes: AssignmentType[];