From a88dbca4fe71c2fbb56fbe790d8476f91add5c14 Mon Sep 17 00:00:00 2001 From: Gavin Wahl Date: Thu, 27 Apr 2017 10:42:41 -0600 Subject: [PATCH] Cache the bug detail page We can do this with no timeout because we have the bug's modified_at timestamp, which changes whenever any action is done on the bug. If we ever implement editing of titles, this will be problematic, because bug mentions include the other bug's title. If the other bug's title gets updated, the cached rendered markdown won't be updated. --- buggy/models.py | 7 +++++++ buggy/templates/buggy/bug_detail.html | 9 +++++++-- buggy/views.py | 7 +------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/buggy/models.py b/buggy/models.py index 897c9ee..bc1ef1f 100644 --- a/buggy/models.py +++ b/buggy/models.py @@ -69,6 +69,13 @@ def number(self): def get_absolute_url(self): return urls.reverse('buggy:bug_detail', kwargs={'bug_number': self.number}) + @property + def actions_preloaded(self): + return self.actions.select_related( + 'user', 'comment', 'setpriority', 'setassignment__assigned_to', + 'setstate', 'setproject', 'settitle', + ).prefetch_related('attachments') + class Action(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT) diff --git a/buggy/templates/buggy/bug_detail.html b/buggy/templates/buggy/bug_detail.html index 0a33138..1127b99 100644 --- a/buggy/templates/buggy/bug_detail.html +++ b/buggy/templates/buggy/bug_detail.html @@ -1,10 +1,12 @@ {% extends "buggy/base.html" %} -{% load buggy_tags thumbnail argonauts absoluteuri %} +{% load buggy_tags thumbnail argonauts absoluteuri cache %} {% block title %}{{ block.super }} - {{ bug.title }}{% endblock %} {% block content %} +{% cache 31536000 bug_detail bug.id bug.modified_at %} + +