Skip to content

Commit

Permalink
cache homepage counts
Browse files Browse the repository at this point in the history
  • Loading branch information
tybug committed Jul 24, 2022
1 parent 9a48122 commit 73cb435
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions home/views/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 73cb435

Please sign in to comment.