[O] Optimize unread count with caching

This commit is contained in:
Hykilpikonna
2019-10-05 13:36:56 -04:00
parent 0f6f27aa15
commit 48fb8c7d4c
@@ -10,11 +10,17 @@ export default class OverallCourse extends Vue
// @ts-ignore // @ts-ignore
@Prop({required: true}) course: Course; @Prop({required: true}) course: Course;
private unread: number = -1;
/** /**
* Count the number of unread assignments * Count the number of unread assignments with cache
*/ */
countUnread(): number countUnread(): number
{ {
return this.course.assignments.filter(a => a.unread).length; if (this.unread == -1)
{
return this.unread = this.course.assignments.filter(a => a.unread).length;
}
else return this.unread;
} }
} }