From 9d8f8d8f39ecb5c62ea257f2d86deccea859c074 Mon Sep 17 00:00:00 2001 From: Daniel Ursache Dogariu Date: Wed, 27 Nov 2024 16:59:11 +0200 Subject: [PATCH] Cache the candidate listing rendered template (#369) --------- Co-authored-by: Tudor Amariei --- backend/hub/templates/hub/candidate/list.html | 2 ++ backend/hub/views.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/hub/templates/hub/candidate/list.html b/backend/hub/templates/hub/candidate/list.html index 7279def6..ed30c065 100644 --- a/backend/hub/templates/hub/candidate/list.html +++ b/backend/hub/templates/hub/candidate/list.html @@ -60,6 +60,7 @@

{% if page_obj %} + {% cache listing_cache_duration listing_cache_key %}
{% if not SINGLE_DOMAIN_ROUND %} @@ -68,6 +69,7 @@

{% include "hub/candidate/components/listing_detail.html" %} {% endif %}

+ {% endcache %} {% endif %}
diff --git a/backend/hub/views.py b/backend/hub/views.py index 7dcbd51d..8e01e9d3 100644 --- a/backend/hub/views.py +++ b/backend/hub/views.py @@ -1,5 +1,6 @@ import logging import unicodedata +import hashlib from datetime import datetime from typing import Dict, List, Optional, Union from urllib.parse import unquote @@ -584,7 +585,6 @@ def _get_candidate_counters(self): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context["listing_cache_duration"] = settings.TIMEOUT_CACHE_SHORT context["current_search"] = self.request.GET.get("q", "") context["should_display_candidates"] = False @@ -600,6 +600,11 @@ def get_context_data(self, **kwargs): context["counters"] = self._get_candidate_counters() context["domains"] = Domain.objects.all() + context["listing_cache_duration"] = settings.TIMEOUT_CACHE_SHORT + # noinspection InsecureHash + context["listing_cache_key"] = hashlib.sha256( + f"candidates_listing_{current_domain if current_domain else ''}_{context['current_search']}".encode() + ).hexdigest() return context