From 0e8226b5d7a6b024dd87366ff019abd2d25ec0a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Mon, 11 Jun 2018 18:32:05 +0300 Subject: [PATCH] Optimize /checks/status: load and parse the template once, not N times. --- hc/front/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hc/front/views.py b/hc/front/views.py index 9b491fa1..4b8a4800 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -11,7 +11,7 @@ from django.db.models import Count from django.http import (Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, JsonResponse) from django.shortcuts import get_object_or_404, redirect, render -from django.template.loader import render_to_string +from django.template.loader import get_template, render_to_string from django.urls import reverse from django.utils import timezone from django.utils.crypto import get_random_string @@ -90,6 +90,7 @@ def status(request): checks = list(Check.objects.filter(user_id=request.team.user_id)) details = [] + tmpl = get_template("front/last_ping_cell.html") for check in checks: status = "grace" if check.in_grace_period() else check.get_status() @@ -97,7 +98,7 @@ def status(request): details.append({ "code": str(check.code), "status": status, - "last_ping": render_to_string("front/last_ping_cell.html", ctx) + "last_ping": tmpl.render(ctx) }) tags_statuses, num_down = _tags_statuses(checks)