From 86d624d2ffce98d8d9f48cc25ec9ac918f3b494c Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Sat, 20 Jul 2024 18:59:16 +0200 Subject: [PATCH] packages: cache package details metadata for 59 seconds For non-logged in users cache the expensive template which calls get_requiredby for 59 seconds, for glibc this spawns 100 queries. --- packages/views/display.py | 3 ++- templates/packages/package_details.html | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/views/display.py b/packages/views/display.py index 9bad3e88..9f4fd5e6 100644 --- a/packages/views/display.py +++ b/packages/views/display.py @@ -138,7 +138,8 @@ def details(request, name='', repo='', arch=''): except RebuilderdStatus.DoesNotExist: pass return render(request, 'packages/details.html', {'pkg': pkg, 'rbstatus': rbstatus, - 'notreproducible': rbstatus.status == RebuilderdStatus.BAD if rbstatus else False}) + 'notreproducible': rbstatus.status == RebuilderdStatus.BAD if rbstatus else False, + 'cache_time': 0 if request.user.is_authenticated else 59}) except Package.DoesNotExist: # attempt a variety of fallback options before 404ing options = (redirect_agnostic, split_package_details, diff --git a/templates/packages/package_details.html b/templates/packages/package_details.html index 47318ac6..7ff236fe 100644 --- a/templates/packages/package_details.html +++ b/templates/packages/package_details.html @@ -1,4 +1,5 @@ {% load humanize %} +{% load cache %} {% load details_link %}

{{ pkg.pkgname }} {{ pkg.full_version }}

@@ -213,6 +214,7 @@

Versions Elsewhere

+ {% cache cache_time package-details-metadata user.is_authenticated %}
{% with deps=pkg.get_depends %}
@@ -251,4 +253,5 @@

+ {% endcache %}