diff options
author | Alban Gruin | 2017-11-25 15:01:48 +0100 |
---|---|---|
committer | Alban Gruin | 2017-11-25 15:01:48 +0100 |
commit | cbab00f4b745f4d80dd06a52699006d1d081be20 (patch) | |
tree | a8f992c76cb4b99c353e5ad430a05d51613a2269 | |
parent | 621f5d7f0d28f7252e1ff0c0f1286824fa55c33e (diff) |
Fusion de group_list et de group_list_common.
Légère modification de la requête pour récupérer les semaines de
cours (au lieu de filtrer par l’emploi du temps, on filtre par les
groupes), résultant en une nette accélération du traitement
Avant modification :
SQLite : ~420ms
PostgreSQL : ~60ms puis ~30ms
Après modification :
SQLite : ~18ms
PostgreSQL : ~23ms puis ~13ms
La progression sur PostgreSQL est celle qui importe le plus, puisqu’il
s’agit du SGBDR utilisé en production, mais la requête s’effectue tout
de même plus rapidement (un peu plus qu’un rapport 2), ce qui reste
intéressant.
-rw-r--r-- | views.py | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -35,11 +35,14 @@ def mention_list(request, year_slug): return render(request, "index.html", {"year": year, "elements": timetables}) -def group_list_common(request, timetable, groups): +def group_list(request, year_slug, timetable_slug): + timetable = get_object_or_404(Timetable, year__slug=year_slug, slug=timetable_slug) + groups = Group.objects.filter(timetable=timetable, hidden=False).order_by("name") + start, _ = get_week(*get_current_week()) end = start + datetime.timedelta(weeks=4) - groups_weeks = Course.objects.get_weeks(begin__gte=start, begin__lt=end, timetable=timetable) \ + groups_weeks = Course.objects.get_weeks(begin__gte=start, begin__lt=end, groups__in=groups) \ .values("groups__mention", "groups__subgroup", "year", "week") @@ -57,12 +60,8 @@ def group_list_common(request, timetable, groups): if hasattr(group, "weeks"): group.weeks.sort() - return render(request, "group_list.html", {"timetable": timetable, "groups": groups}) -def group_list(request, year_slug, timetable_slug): - timetable = get_object_or_404(Timetable, year__slug=year_slug, slug=timetable_slug) - groups = Group.objects.filter(timetable=timetable).order_by("name") - return group_list_common(request, timetable, groups) + return render(request, "group_list.html", {"timetable": timetable, "groups": groups}) def timetable(request, year_slug, timetable_slug, group_slug, year=None, week=None): current_year, current_week = get_current_or_next_week() |