Merge lp:~jtv/launchpad/cleanups-475435 into lp:launchpad

Proposed by Jeroen T. Vermeulen
Status: Rejected
Rejected by: Jeroen T. Vermeulen
Proposed branch: lp:~jtv/launchpad/cleanups-475435
Merge into: lp:launchpad
Diff against target: 111 lines (+18/-25)
4 files modified
lib/lp/translations/interfaces/potemplate.py (+7/-5)
lib/lp/translations/model/pofile.py (+2/-10)
lib/lp/translations/model/potemplate.py (+8/-9)
lib/lp/translations/templates/object-templates.pt (+1/-1)
To merge this branch: bzr merge lp:~jtv/launchpad/cleanups-475435
Reviewer Review Type Date Requested Status
Muharem Hrnjadovic code Pending
Review via email: mp+21070@code.launchpad.net

Commit message

Cleanups instead of fix for bug 475435.

Description of the change

= Cleanups for bug 475435 =

Bug 7475435 turns out to be triaged as High but actually considered Low. But while I was looking into these timeouts, I came up with some cleanups that are nice to have anyway.

This is all semantically neutral: make use of some caching (the cached value isn't ever supposed to fall out of sync anyway), improve some docstrings, simplify some queries, remove some commented-out code. It should make a few things slightly faster, but nothing dramatic.

No lint.

Jeroen

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/translations/interfaces/potemplate.py'
--- lib/lp/translations/interfaces/potemplate.py 2009-11-27 12:50:16 +0000
+++ lib/lp/translations/interfaces/potemplate.py 2010-03-10 18:38:19 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the1# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4# pylint: disable-msg=E0211,E02134# pylint: disable-msg=E0211,E0213
@@ -377,10 +377,12 @@
377 """377 """
378378
379 def getPOTMsgSetsCount(current=True):379 def getPOTMsgSetsCount(current=True):
380 """Return the number of POTMsgSet objects related to this object.380 """Count the number of `POTMsgSet`s in this template.
381381
382 The current argument is used to select only current POTMsgSets or all382 Use this in recomputing statistics. Otherwise, use
383 of them.383 `messageCount` which relies on a cached count instead.
384
385 :param current: Count only messages that are currently in use?
384 """386 """
385387
386 def __getitem__(key):388 def __getitem__(key):
387389
=== modified file 'lib/lp/translations/model/pofile.py'
--- lib/lp/translations/model/pofile.py 2010-01-14 16:39:18 +0000
+++ lib/lp/translations/model/pofile.py 2010-03-10 18:38:19 +0000
@@ -378,8 +378,7 @@
378 Orders the result by TranslationTemplateItem.sequence which must378 Orders the result by TranslationTemplateItem.sequence which must
379 be among `origin_tables`.379 be among `origin_tables`.
380 """380 """
381 store = getUtility(IStoreSelector).get(MAIN_STORE, MASTER_FLAVOR)381 results = Store.of(self).using(origin_tables).find(
382 results = store.using(origin_tables).find(
383 POTMsgSet, SQL(query))382 POTMsgSet, SQL(query))
384 return results.order_by(TranslationTemplateItem.sequence)383 return results.order_by(TranslationTemplateItem.sequence)
385384
@@ -609,13 +608,6 @@
609 def translated(self):608 def translated(self):
610 """See `IPOFile`."""609 """See `IPOFile`."""
611 raise NotImplementedError610 raise NotImplementedError
612 # return iter(TranslationMessage.select('''
613 # POMsgSet.pofile = %d AND
614 # POMsgSet.iscomplete=TRUE AND
615 # POMsgSet.potmsgset = POTMsgSet.id AND
616 # POTMsgSet.sequence > 0''' % self.id,
617 # clauseTables = ['POMsgSet']
618 # ))
619611
620 def untranslated(self):612 def untranslated(self):
621 """See `IPOFile`."""613 """See `IPOFile`."""
@@ -963,7 +955,7 @@
963 if self.potemplate.messageCount() > 0:955 if self.potemplate.messageCount() > 0:
964 total = self.potemplate.messageCount()956 total = self.potemplate.messageCount()
965 else:957 else:
966 total = self.potemplate.getPOTMsgSets().count()958 total = self.potemplate.getPOTMsgSetsCount()
967 self.potemplate.messagecount = total959 self.potemplate.messagecount = total
968960
969 # Get number of translations done only in Launchpad.961 # Get number of translations done only in Launchpad.
970962
=== modified file 'lib/lp/translations/model/potemplate.py'
--- lib/lp/translations/model/potemplate.py 2010-01-12 21:29:03 +0000
+++ lib/lp/translations/model/potemplate.py 2010-03-10 18:38:19 +0000
@@ -326,13 +326,10 @@
326326
327 @property327 @property
328 def language_count(self):328 def language_count(self):
329 return Language.select('''329 return Store.of(self).find(
330 POFile.language = Language.id AND330 POFile,
331 POFile.currentcount + POFile.rosettacount > 0 AND331 POFile.potemplate == self,
332 POFile.potemplate = %s332 POFile.rosettacount > 0).count()
333 ''' % sqlvalues(self.id),
334 clauseTables=['POFile'],
335 distinct=True).count()
336333
337 @property334 @property
338 def translationtarget(self):335 def translationtarget(self):
@@ -442,8 +439,10 @@
442439
443 def getPOTMsgSetsCount(self, current=True):440 def getPOTMsgSetsCount(self, current=True):
444 """See `IPOTemplate`."""441 """See `IPOTemplate`."""
445 results = self.getPOTMsgSets(current, prefetch=False)442 clauses = (TranslationTemplateItem.potmsgset == self)
446 return results.count()443 if current:
444 clauses = And(clauses, TranslationTemplateItem.sequence > 0)
445 return Store.of(self).find(TranslationTemplateItem, clauses).count()
447446
448 def getPOTMsgSetByID(self, id):447 def getPOTMsgSetByID(self, id):
449 """See `IPOTemplate`."""448 """See `IPOTemplate`."""
450449
=== modified file 'lib/lp/translations/templates/object-templates.pt'
--- lib/lp/translations/templates/object-templates.pt 2010-02-15 16:00:01 +0000
+++ lib/lp/translations/templates/object-templates.pt 2010-03-10 18:38:19 +0000
@@ -108,7 +108,7 @@
108 </tal:inactive>108 </tal:inactive>
109 </td>109 </td>
110 <td class="length_column"110 <td class="length_column"
111 tal:content="template/getPOTMsgSetsCount">1777</td>111 tal:content="template/messageCount">1777</td>
112 <td class="languages_column"112 <td class="languages_column"
113 tal:content="template/language_count">777</td>113 tal:content="template/language_count">777</td>
114 <td class="lastupdate_column">114 <td class="lastupdate_column">