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
=== modified file 'lib/lp/translations/browser/tests/translationmessage-views.txt'
--- lib/lp/translations/browser/tests/translationmessage-views.txt 2014-02-19 04:01:46 +0000
+++ lib/lp/translations/browser/tests/translationmessage-views.txt 2014-06-13 08:17:07 +0000
@@ -519,33 +519,6 @@
519 0519 0
520520
521521
522Sequence number of new shared POTMsgSets
523----------------------------------------
524
525Newly added shared POTMsgSets don't have their sequence field set, but
526they do have sequence number when being displayed with translation
527message.
528
529 >>> pofile = factory.makePOFile('sr')
530 >>> potemplate = pofile.potemplate
531 >>> potmsgset = factory.makePOTMsgSet(potemplate, sequence=1)
532 >>> potmsgset.getSequence(potemplate)
533 1
534 >>> translationmessage = factory.makeCurrentTranslationMessage(
535 ... pofile=pofile, potmsgset=potmsgset,
536 ... translations=[u"some translation"])
537 >>> translationmessage.setPOFile(pofile)
538 >>> server_url = '/'.join(
539 ... [canonical_url(translationmessage), '+translate'])
540 >>> translationmessage_page_view = create_view(
541 ... translationmessage, "+translate", server_url=server_url)
542 >>> translationmessage_page_view.initialize()
543 >>> subview = translationmessage_page_view.translationmessage_view
544 >>> subview.initialize()
545 >>> subview.sequence
546 1
547
548
549Sharing and diverging messages522Sharing and diverging messages
550------------------------------523------------------------------
551524
552525
=== modified file 'lib/lp/translations/browser/translationmessage.py'
--- lib/lp/translations/browser/translationmessage.py 2014-02-26 03:05:44 +0000
+++ lib/lp/translations/browser/translationmessage.py 2014-06-13 08:17:07 +0000
@@ -1457,12 +1457,6 @@
1457 self.context.potmsgset),1457 self.context.potmsgset),
1458 self.context.potmsgset.flags)1458 self.context.potmsgset.flags)
14591459
1460 @cachedproperty
1461 def sequence(self):
1462 """Return the position number of this potmsgset in the pofile."""
1463 return self.context.potmsgset.getSequence(
1464 self.pofile.potemplate)
1465
1466 @property1460 @property
1467 def singular_text(self):1461 def singular_text(self):
1468 """Return the singular form prepared to render in a web page."""1462 """Return the singular form prepared to render in a web page."""
@@ -1579,7 +1573,8 @@
1579 # should point to the parent batch of messages.1573 # should point to the parent batch of messages.
1580 # XXX: kiko 2006-09-27: Preserve second_lang_code and other form1574 # XXX: kiko 2006-09-27: Preserve second_lang_code and other form
1581 # parameters?1575 # parameters?
1582 batch_url = '/+translate?start=%d' % (self.sequence - 1)1576 assert self.context.browser_pofile == self.pofile
1577 batch_url = '/+translate?start=%d' % (self.context.sequence - 1)
1583 return canonical_url(self.pofile) + batch_url1578 return canonical_url(self.pofile) + batch_url
15841579
1585 @property1580 @property
15861581
=== modified file 'lib/lp/translations/model/translationmessage.py'
--- lib/lp/translations/model/translationmessage.py 2013-06-20 05:50:00 +0000
+++ lib/lp/translations/model/translationmessage.py 2014-06-13 08:17:07 +0000
@@ -37,7 +37,10 @@
37 SQLBase,37 SQLBase,
38 sqlvalues,38 sqlvalues,
39 )39 )
40from lp.services.propertycache import cachedproperty40from lp.services.propertycache import (
41 cachedproperty,
42 get_property_cache,
43 )
41from lp.translations.interfaces.side import TranslationSide44from lp.translations.interfaces.side import TranslationSide
42from lp.translations.interfaces.translationmessage import (45from lp.translations.interfaces.translationmessage import (
43 ITranslationMessage,46 ITranslationMessage,
@@ -113,8 +116,9 @@
113 def setPOFile(self, pofile):116 def setPOFile(self, pofile):
114 """See `ITranslationMessage`."""117 """See `ITranslationMessage`."""
115 self.browser_pofile = pofile118 self.browser_pofile = pofile
119 del get_property_cache(self).sequence
116120
117 @property121 @cachedproperty
118 def sequence(self):122 def sequence(self):
119 if self.browser_pofile:123 if self.browser_pofile:
120 pofile = self.browser_pofile124 pofile = self.browser_pofile
121125
=== modified file 'lib/lp/translations/templates/currenttranslationmessage-translate-one.pt'
--- lib/lp/translations/templates/currenttranslationmessage-translate-one.pt 2012-03-02 16:17:46 +0000
+++ lib/lp/translations/templates/currenttranslationmessage-translate-one.pt 2014-06-13 08:17:07 +0000
@@ -17,7 +17,7 @@
17 </td>17 </td>
18 <td style="text-align: right;">18 <td style="text-align: right;">
19 <div tal:attributes="id string:${view/html_id}">19 <div tal:attributes="id string:${view/html_id}">
20 <span tal:replace="view/sequence">1</span>.20 <span tal:replace="context/sequence">1</span>.
21 <input21 <input
22 type="hidden"22 type="hidden"
23 tal:condition="view/form_is_writeable"23 tal:condition="view/form_is_writeable"