Skip to content

Commit

Permalink
packages: cache package details metadata for 59 seconds
Browse files Browse the repository at this point in the history
For non-logged in users cache the expensive template which calls
get_requiredby for 59 seconds, for glibc this spawns 100 queries.
  • Loading branch information
jelly committed Jul 20, 2024
1 parent 1101323 commit 86d624d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/views/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions templates/packages/package_details.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load humanize %}
{% load cache %}
{% load details_link %}
<div id="pkgdetails" class="box">
<h2>{{ pkg.pkgname }} {{ pkg.full_version }}</h2>
Expand Down Expand Up @@ -213,6 +214,7 @@ <h4>Versions Elsewhere</h4>
</table>
</div>

{% cache cache_time package-details-metadata user.is_authenticated %}
<div id="metadata">
{% with deps=pkg.get_depends %}
<div id="pkgdeps" class="listing">
Expand Down Expand Up @@ -251,4 +253,5 @@ <h3 title="Complete list of so-names the package links too">
</div>
</div>
</div>
{% endcache %}
</div>

0 comments on commit 86d624d

Please sign in to comment.