Skip to content

Commit

Permalink
Cache the candidate listing rendered template (#369)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Tudor Amariei <tudor.amariei@commitglobal.org>
  • Loading branch information
danniel and tudoramariei authored Nov 27, 2024
1 parent 093bc1e commit 9d8f8d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions backend/hub/templates/hub/candidate/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ <h2 class="section-title uppercase">
<div class="container">
{% if page_obj %}

{% cache listing_cache_duration listing_cache_key %}
<div class="is-multiline infinite-container">

{% if not SINGLE_DOMAIN_ROUND %}
Expand All @@ -68,6 +69,7 @@ <h2 class="section-title uppercase">
{% include "hub/candidate/components/listing_detail.html" %}
{% endif %}
</div>
{% endcache %}

{% endif %}
</div>
Expand Down
7 changes: 6 additions & 1 deletion backend/hub/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 9d8f8d8

Please sign in to comment.