Merge lp:~wgrant/launchpad/bug-736005-begins into lp:launchpad

Proposed by William Grant
Status: Merged
Merged at revision: 17046
Proposed branch: lp:~wgrant/launchpad/bug-736005-begins
Merge into: lp:launchpad
Diff against target: 104 lines (+9/-37)
4 files modified
lib/lp/translations/browser/tests/translationmessage-views.txt (+0/-27)
lib/lp/translations/browser/translationmessage.py (+2/-7)
lib/lp/translations/model/translationmessage.py (+6/-2)
lib/lp/translations/templates/currenttranslationmessage-translate-one.pt (+1/-1)
To merge this branch: bzr merge lp:~wgrant/launchpad/bug-736005-begins
Reviewer Review Type Date Requested Status
Celso Providelo (community) Approve
Review via email: mp+223035@code.launchpad.net

Commit message

Turn TranslationMessageMixIn.sequence into a cachedproperty, invalidating it when browser_pofile is set. Use it everywhere possible, cutting POFile:+translate query counts by up to 20%.

Description of the change

Turn TranslationMessageMixIn.sequence into a cachedproperty, invalidating it when browser_pofile is set. Use it everywhere possible, cutting POFile:+translate query counts by up to 20%.

To post a comment you must log in.
Revision history for this message
Celso Providelo (cprov) wrote :

Let's crop this low-hanging fruit, very good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/translations/browser/tests/translationmessage-views.txt'
2--- lib/lp/translations/browser/tests/translationmessage-views.txt 2014-02-19 04:01:46 +0000
3+++ lib/lp/translations/browser/tests/translationmessage-views.txt 2014-06-13 08:17:07 +0000
4@@ -519,33 +519,6 @@
5 0
6
7
8-Sequence number of new shared POTMsgSets
9-----------------------------------------
10-
11-Newly added shared POTMsgSets don't have their sequence field set, but
12-they do have sequence number when being displayed with translation
13-message.
14-
15- >>> pofile = factory.makePOFile('sr')
16- >>> potemplate = pofile.potemplate
17- >>> potmsgset = factory.makePOTMsgSet(potemplate, sequence=1)
18- >>> potmsgset.getSequence(potemplate)
19- 1
20- >>> translationmessage = factory.makeCurrentTranslationMessage(
21- ... pofile=pofile, potmsgset=potmsgset,
22- ... translations=[u"some translation"])
23- >>> translationmessage.setPOFile(pofile)
24- >>> server_url = '/'.join(
25- ... [canonical_url(translationmessage), '+translate'])
26- >>> translationmessage_page_view = create_view(
27- ... translationmessage, "+translate", server_url=server_url)
28- >>> translationmessage_page_view.initialize()
29- >>> subview = translationmessage_page_view.translationmessage_view
30- >>> subview.initialize()
31- >>> subview.sequence
32- 1
33-
34-
35 Sharing and diverging messages
36 ------------------------------
37
38
39=== modified file 'lib/lp/translations/browser/translationmessage.py'
40--- lib/lp/translations/browser/translationmessage.py 2014-02-26 03:05:44 +0000
41+++ lib/lp/translations/browser/translationmessage.py 2014-06-13 08:17:07 +0000
42@@ -1457,12 +1457,6 @@
43 self.context.potmsgset),
44 self.context.potmsgset.flags)
45
46- @cachedproperty
47- def sequence(self):
48- """Return the position number of this potmsgset in the pofile."""
49- return self.context.potmsgset.getSequence(
50- self.pofile.potemplate)
51-
52 @property
53 def singular_text(self):
54 """Return the singular form prepared to render in a web page."""
55@@ -1579,7 +1573,8 @@
56 # should point to the parent batch of messages.
57 # XXX: kiko 2006-09-27: Preserve second_lang_code and other form
58 # parameters?
59- batch_url = '/+translate?start=%d' % (self.sequence - 1)
60+ assert self.context.browser_pofile == self.pofile
61+ batch_url = '/+translate?start=%d' % (self.context.sequence - 1)
62 return canonical_url(self.pofile) + batch_url
63
64 @property
65
66=== modified file 'lib/lp/translations/model/translationmessage.py'
67--- lib/lp/translations/model/translationmessage.py 2013-06-20 05:50:00 +0000
68+++ lib/lp/translations/model/translationmessage.py 2014-06-13 08:17:07 +0000
69@@ -37,7 +37,10 @@
70 SQLBase,
71 sqlvalues,
72 )
73-from lp.services.propertycache import cachedproperty
74+from lp.services.propertycache import (
75+ cachedproperty,
76+ get_property_cache,
77+ )
78 from lp.translations.interfaces.side import TranslationSide
79 from lp.translations.interfaces.translationmessage import (
80 ITranslationMessage,
81@@ -113,8 +116,9 @@
82 def setPOFile(self, pofile):
83 """See `ITranslationMessage`."""
84 self.browser_pofile = pofile
85+ del get_property_cache(self).sequence
86
87- @property
88+ @cachedproperty
89 def sequence(self):
90 if self.browser_pofile:
91 pofile = self.browser_pofile
92
93=== modified file 'lib/lp/translations/templates/currenttranslationmessage-translate-one.pt'
94--- lib/lp/translations/templates/currenttranslationmessage-translate-one.pt 2012-03-02 16:17:46 +0000
95+++ lib/lp/translations/templates/currenttranslationmessage-translate-one.pt 2014-06-13 08:17:07 +0000
96@@ -17,7 +17,7 @@
97 </td>
98 <td style="text-align: right;">
99 <div tal:attributes="id string:${view/html_id}">
100- <span tal:replace="view/sequence">1</span>.
101+ <span tal:replace="context/sequence">1</span>.
102 <input
103 type="hidden"
104 tal:condition="view/form_is_writeable"