Merge lp:~stub/launchpad/cache-bugcomments into lp:launchpad

Proposed by Stuart Bishop
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 11045
Proposed branch: lp:~stub/launchpad/cache-bugcomments
Merge into: lp:launchpad
Prerequisite: lp:~stub/launchpad/memcache
Diff against target: 107 lines (+46/-6)
3 files modified
lib/lp/bugs/browser/bugcomment.py (+37/-1)
lib/lp/bugs/interfaces/bugmessage.py (+2/-0)
lib/lp/bugs/templates/bugcomment-box.pt (+7/-5)
To merge this branch: bzr merge lp:~stub/launchpad/cache-bugcomments
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+28177@code.launchpad.net

Commit message

Cache bug comments much more aggressively.

Description of the change

Cache bug comments much more aggressively.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Full test suite has not yet been run so there may be fallout. Sending to ec2.

Revision history for this message
Graham Binns (gmb) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/browser/bugcomment.py'
2--- lib/lp/bugs/browser/bugcomment.py 2010-03-22 16:49:55 +0000
3+++ lib/lp/bugs/browser/bugcomment.py 2010-06-23 03:29:30 +0000
4@@ -10,11 +10,14 @@
5 'BugCommentBoxView',
6 'BugCommentBoxExpandedReplyView',
7 'BugCommentXHTMLRepresentation',
8- 'BugMessageBreadcrumb',
9+ 'BugCommentBreadcrumb',
10 'build_comments_from_chunks',
11 'should_display_remote_comments',
12 ]
13
14+from datetime import datetime, timedelta
15+from pytz import utc
16+
17 from zope.component import adapts, getMultiAdapter, getUtility
18 from zope.interface import implements, Interface
19
20@@ -213,6 +216,39 @@
21 else:
22 return False
23
24+ @property
25+ def rendered_cache_time(self):
26+ """The number of seconds we can cache the rendered comment for.
27+
28+ Bug comments are cached with 'authenticated' visibility, so
29+ should contain no information hidden from some users. We use
30+ 'authenticated' rather than 'public' as email addresses are
31+ obfuscated for unauthenticated users.
32+ """
33+ now = datetime.now(tz=utc)
34+ # The major factor in how long we can cache a bug comment is
35+ # the timestamp. The rendering of the timestamp changes every
36+ # minute for the first hour because we say '7 minutes ago'.
37+ if self.datecreated > now - timedelta(hours=1):
38+ return 60
39+
40+ # Don't cache for long if we are waiting for synchronization.
41+ elif self.bugwatch and not self.synchronized:
42+ return 5*60
43+
44+ # For the rest of the first day, the rendering changes every
45+ # hour. '4 hours ago'. Expire in 15 minutes so the timestamp
46+ # is at most 15 minutes out of date.
47+ elif self.datecreated > now - timedelta(days=1):
48+ return 15*60
49+
50+ # Otherwise, cache away. Lets cache for 6 hours. We don't want
51+ # to cache for too long as there are still things that can
52+ # become stale - eg. if a bug attachment has been deleted we
53+ # should stop rendering the link.
54+ else:
55+ return 6*60*60
56+
57
58 class BugCommentView(LaunchpadView):
59 """View for a single bug comment."""
60
61=== modified file 'lib/lp/bugs/interfaces/bugmessage.py'
62--- lib/lp/bugs/interfaces/bugmessage.py 2010-01-12 09:38:00 +0000
63+++ lib/lp/bugs/interfaces/bugmessage.py 2010-06-23 03:29:30 +0000
64@@ -127,3 +127,5 @@
65 "Whether or not to show a footer for the comment.")
66 patches = Attribute(
67 "Patches attched to this comment.")
68+ rendered_cache_time = Attribute(
69+ "How long we can cache the rendered comment for.")
70
71=== modified file 'lib/lp/bugs/templates/bugcomment-box.pt'
72--- lib/lp/bugs/templates/bugcomment-box.pt 2010-04-06 07:27:01 +0000
73+++ lib/lp/bugs/templates/bugcomment-box.pt 2010-06-23 03:29:30 +0000
74@@ -8,7 +8,8 @@
75 admin_comment_hidden_class
76 python: comment.show_for_admin and 'adminHiddenComment' or ''"
77 tal:attributes="class string:boardComment ${remote_bug_comment_class}
78- ${admin_comment_hidden_class}">
79+ ${admin_comment_hidden_class}"
80+ tal:content="cache:authenticated,comment/rendered_cache_time,comment/index">
81
82 <div class="boardCommentDetails">
83 <table>
84@@ -55,9 +56,11 @@
85
86 <div class="boardCommentBody">
87 <ul tal:condition="comment/bugattachments" style="margin-bottom: 1em">
88- <li tal:repeat="attachment comment/bugattachments" class="download-attachment">
89+ <li tal:repeat="attachment comment/bugattachments"
90+ class="download-attachment">
91 <a tal:attributes="href attachment/libraryfile/http_url"
92- tal:content="attachment/title" class="sprite download-icon">foo.txt</a>
93+ tal:content="attachment/title"
94+ class="sprite download-icon">foo.txt</a>
95 (<span
96 tal:replace="attachment/libraryfile/content/filesize/fmt:bytes" />,
97 <span tal:replace="attachment/libraryfile/mimetype" />)
98@@ -83,8 +86,7 @@
99 <a tal:attributes="href comment/fmt:url">Read more...</a>
100 </p>
101 </div>
102- <div class="boardCommentFooter" tal:condition="comment/show_footer"
103- tal:content="cache:authenticated,30 minutes,comment/index">
104+ <div class="boardCommentFooter" tal:condition="comment/show_footer">
105 <tal:activity
106 define="activity_list comment/activity"
107 condition="comment/activity">