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
=== modified file 'lib/lp/bugs/browser/bugcomment.py'
--- lib/lp/bugs/browser/bugcomment.py 2010-03-22 16:49:55 +0000
+++ lib/lp/bugs/browser/bugcomment.py 2010-06-23 03:29:30 +0000
@@ -10,11 +10,14 @@
10 'BugCommentBoxView',10 'BugCommentBoxView',
11 'BugCommentBoxExpandedReplyView',11 'BugCommentBoxExpandedReplyView',
12 'BugCommentXHTMLRepresentation',12 'BugCommentXHTMLRepresentation',
13 'BugMessageBreadcrumb',13 'BugCommentBreadcrumb',
14 'build_comments_from_chunks',14 'build_comments_from_chunks',
15 'should_display_remote_comments',15 'should_display_remote_comments',
16 ]16 ]
1717
18from datetime import datetime, timedelta
19from pytz import utc
20
18from zope.component import adapts, getMultiAdapter, getUtility21from zope.component import adapts, getMultiAdapter, getUtility
19from zope.interface import implements, Interface22from zope.interface import implements, Interface
2023
@@ -213,6 +216,39 @@
213 else:216 else:
214 return False217 return False
215218
219 @property
220 def rendered_cache_time(self):
221 """The number of seconds we can cache the rendered comment for.
222
223 Bug comments are cached with 'authenticated' visibility, so
224 should contain no information hidden from some users. We use
225 'authenticated' rather than 'public' as email addresses are
226 obfuscated for unauthenticated users.
227 """
228 now = datetime.now(tz=utc)
229 # The major factor in how long we can cache a bug comment is
230 # the timestamp. The rendering of the timestamp changes every
231 # minute for the first hour because we say '7 minutes ago'.
232 if self.datecreated > now - timedelta(hours=1):
233 return 60
234
235 # Don't cache for long if we are waiting for synchronization.
236 elif self.bugwatch and not self.synchronized:
237 return 5*60
238
239 # For the rest of the first day, the rendering changes every
240 # hour. '4 hours ago'. Expire in 15 minutes so the timestamp
241 # is at most 15 minutes out of date.
242 elif self.datecreated > now - timedelta(days=1):
243 return 15*60
244
245 # Otherwise, cache away. Lets cache for 6 hours. We don't want
246 # to cache for too long as there are still things that can
247 # become stale - eg. if a bug attachment has been deleted we
248 # should stop rendering the link.
249 else:
250 return 6*60*60
251
216252
217class BugCommentView(LaunchpadView):253class BugCommentView(LaunchpadView):
218 """View for a single bug comment."""254 """View for a single bug comment."""
219255
=== modified file 'lib/lp/bugs/interfaces/bugmessage.py'
--- lib/lp/bugs/interfaces/bugmessage.py 2010-01-12 09:38:00 +0000
+++ lib/lp/bugs/interfaces/bugmessage.py 2010-06-23 03:29:30 +0000
@@ -127,3 +127,5 @@
127 "Whether or not to show a footer for the comment.")127 "Whether or not to show a footer for the comment.")
128 patches = Attribute(128 patches = Attribute(
129 "Patches attched to this comment.")129 "Patches attched to this comment.")
130 rendered_cache_time = Attribute(
131 "How long we can cache the rendered comment for.")
130132
=== modified file 'lib/lp/bugs/templates/bugcomment-box.pt'
--- lib/lp/bugs/templates/bugcomment-box.pt 2010-04-06 07:27:01 +0000
+++ lib/lp/bugs/templates/bugcomment-box.pt 2010-06-23 03:29:30 +0000
@@ -8,7 +8,8 @@
8 admin_comment_hidden_class8 admin_comment_hidden_class
9 python: comment.show_for_admin and 'adminHiddenComment' or ''"9 python: comment.show_for_admin and 'adminHiddenComment' or ''"
10 tal:attributes="class string:boardComment ${remote_bug_comment_class}10 tal:attributes="class string:boardComment ${remote_bug_comment_class}
11 ${admin_comment_hidden_class}">11 ${admin_comment_hidden_class}"
12 tal:content="cache:authenticated,comment/rendered_cache_time,comment/index">
1213
13 <div class="boardCommentDetails">14 <div class="boardCommentDetails">
14 <table>15 <table>
@@ -55,9 +56,11 @@
5556
56 <div class="boardCommentBody">57 <div class="boardCommentBody">
57 <ul tal:condition="comment/bugattachments" style="margin-bottom: 1em">58 <ul tal:condition="comment/bugattachments" style="margin-bottom: 1em">
58 <li tal:repeat="attachment comment/bugattachments" class="download-attachment">59 <li tal:repeat="attachment comment/bugattachments"
60 class="download-attachment">
59 <a tal:attributes="href attachment/libraryfile/http_url"61 <a tal:attributes="href attachment/libraryfile/http_url"
60 tal:content="attachment/title" class="sprite download-icon">foo.txt</a>62 tal:content="attachment/title"
63 class="sprite download-icon">foo.txt</a>
61 (<span64 (<span
62 tal:replace="attachment/libraryfile/content/filesize/fmt:bytes" />,65 tal:replace="attachment/libraryfile/content/filesize/fmt:bytes" />,
63 <span tal:replace="attachment/libraryfile/mimetype" />)66 <span tal:replace="attachment/libraryfile/mimetype" />)
@@ -83,8 +86,7 @@
83 <a tal:attributes="href comment/fmt:url">Read more...</a>86 <a tal:attributes="href comment/fmt:url">Read more...</a>
84 </p>87 </p>
85 </div>88 </div>
86 <div class="boardCommentFooter" tal:condition="comment/show_footer"89 <div class="boardCommentFooter" tal:condition="comment/show_footer">
87 tal:content="cache:authenticated,30 minutes,comment/index">
88 <tal:activity90 <tal:activity
89 define="activity_list comment/activity"91 define="activity_list comment/activity"
90 condition="comment/activity">92 condition="comment/activity">