launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #16909
[Merge] lp:~wgrant/launchpad/bug-736005-begins into lp:launchpad
William Grant has proposed merging lp:~wgrant/launchpad/bug-736005-begins into lp:launchpad.
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%.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~wgrant/launchpad/bug-736005-begins/+merge/223035
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%.
--
https://code.launchpad.net/~wgrant/launchpad/bug-736005-begins/+merge/223035
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/bug-736005-begins into lp:launchpad.
=== 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 @@
0
-Sequence number of new shared POTMsgSets
-----------------------------------------
-
-Newly added shared POTMsgSets don't have their sequence field set, but
-they do have sequence number when being displayed with translation
-message.
-
- >>> pofile = factory.makePOFile('sr')
- >>> potemplate = pofile.potemplate
- >>> potmsgset = factory.makePOTMsgSet(potemplate, sequence=1)
- >>> potmsgset.getSequence(potemplate)
- 1
- >>> translationmessage = factory.makeCurrentTranslationMessage(
- ... pofile=pofile, potmsgset=potmsgset,
- ... translations=[u"some translation"])
- >>> translationmessage.setPOFile(pofile)
- >>> server_url = '/'.join(
- ... [canonical_url(translationmessage), '+translate'])
- >>> translationmessage_page_view = create_view(
- ... translationmessage, "+translate", server_url=server_url)
- >>> translationmessage_page_view.initialize()
- >>> subview = translationmessage_page_view.translationmessage_view
- >>> subview.initialize()
- >>> subview.sequence
- 1
-
-
Sharing and diverging messages
------------------------------
=== 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 @@
self.context.potmsgset),
self.context.potmsgset.flags)
- @cachedproperty
- def sequence(self):
- """Return the position number of this potmsgset in the pofile."""
- return self.context.potmsgset.getSequence(
- self.pofile.potemplate)
-
@property
def singular_text(self):
"""Return the singular form prepared to render in a web page."""
@@ -1579,7 +1573,8 @@
# should point to the parent batch of messages.
# XXX: kiko 2006-09-27: Preserve second_lang_code and other form
# parameters?
- batch_url = '/+translate?start=%d' % (self.sequence - 1)
+ assert self.context.browser_pofile == self.pofile
+ batch_url = '/+translate?start=%d' % (self.context.sequence - 1)
return canonical_url(self.pofile) + batch_url
@property
=== 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 @@
SQLBase,
sqlvalues,
)
-from lp.services.propertycache import cachedproperty
+from lp.services.propertycache import (
+ cachedproperty,
+ get_property_cache,
+ )
from lp.translations.interfaces.side import TranslationSide
from lp.translations.interfaces.translationmessage import (
ITranslationMessage,
@@ -113,8 +116,9 @@
def setPOFile(self, pofile):
"""See `ITranslationMessage`."""
self.browser_pofile = pofile
+ del get_property_cache(self).sequence
- @property
+ @cachedproperty
def sequence(self):
if self.browser_pofile:
pofile = self.browser_pofile
=== 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 @@
</td>
<td style="text-align: right;">
<div tal:attributes="id string:${view/html_id}">
- <span tal:replace="view/sequence">1</span>.
+ <span tal:replace="context/sequence">1</span>.
<input
type="hidden"
tal:condition="view/form_is_writeable"
Follow ups