Commit 59eed7be198e9b161b75a93a5335005c7ac7cafe
1 parent
23e4b7a71e
Exists in
master
improve section search performance
Showing 2 changed files with 7 additions and 2 deletions Side-by-side Diff
flashcards/models.py
View file @
59eed7b
... | ... | @@ -468,7 +468,7 @@ |
468 | 468 | q |= Q(course_num__icontains=term) |
469 | 469 | q |= Q(instructor__icontains=term) |
470 | 470 | final_q &= q |
471 | - qs = cls.objects.filter(final_q) | |
471 | + qs = cls.objects.filter(final_q).prefetch_related('whitelist') | |
472 | 472 | # Have the database cast the course number to an integer so it will sort properly |
473 | 473 | # ECE 35 should rank before ECE 135 even though '135' < '35' lexicographically |
474 | 474 | qs = qs.extra(select={'course_num_int': "CAST(rtrim(course_num, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') AS INTEGER)"}) |
... | ... | @@ -480,7 +480,11 @@ |
480 | 480 | """ |
481 | 481 | :return: whether a whitelist exists for this section |
482 | 482 | """ |
483 | - return self.whitelist.exists() | |
483 | + data = cache.get("section_%d_is_whitelisted" % self.pk) | |
484 | + if data is None: | |
485 | + data = self.whitelist.exists() | |
486 | + cache.set("section_%d_is_whitelisted" % self.pk, data, 24 * 60 * 60) | |
487 | + return data | |
484 | 488 | |
485 | 489 | def is_user_on_whitelist(self, user): |
486 | 490 | """ |