From 73cb43567b4af120fbd4eb79c27f99ff9ae26142 Mon Sep 17 00:00:00 2001 From: Liam DeVoe Date: Sat, 21 May 2022 13:06:47 -0400 Subject: [PATCH] cache homepage counts --- home/views/basic.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/home/views/basic.py b/home/views/basic.py index cc0197fb..2c1fcbf0 100644 --- a/home/views/basic.py +++ b/home/views/basic.py @@ -8,7 +8,7 @@ from home.models import Organization, Professor, Course, Review, Grade, User from home.tables.reviews_table import VerifiedReviewsTable, ProfileReviewsTable from home.forms.basic import ProfileForm -from home.utils import recompute_ttl_cache +from home.utils import recompute_ttl_cache, ttl_cache class About(View): def get(self, request): @@ -73,12 +73,20 @@ def get(self, request, name): return render(request, "course_reviews.html", context) class Index(View): - def get(self, request): + + @staticmethod + @ttl_cache(24 * 60 * 60 * 7) + def get_counts(): num_courses = Course.unfiltered.count() num_professors = Professor.verified.count() num_reviews = Review.verified.count() num_course_grades = Grade.unfiltered.count() + return (num_courses, num_professors, num_reviews, num_course_grades) + + def get(self, request): + counts = self.get_counts() + num_courses, num_professors, num_reviews, num_course_grades = counts recent_reviews = ( Review .verified