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
1=== modified file 'lib/lp/translations/interfaces/potemplate.py'
2--- lib/lp/translations/interfaces/potemplate.py 2009-11-27 12:50:16 +0000
3+++ lib/lp/translations/interfaces/potemplate.py 2010-03-10 18:38:19 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 # pylint: disable-msg=E0211,E0213
10@@ -377,10 +377,12 @@
11 """
12
13 def getPOTMsgSetsCount(current=True):
14- """Return the number of POTMsgSet objects related to this object.
15-
16- The current argument is used to select only current POTMsgSets or all
17- of them.
18+ """Count the number of `POTMsgSet`s in this template.
19+
20+ Use this in recomputing statistics. Otherwise, use
21+ `messageCount` which relies on a cached count instead.
22+
23+ :param current: Count only messages that are currently in use?
24 """
25
26 def __getitem__(key):
27
28=== modified file 'lib/lp/translations/model/pofile.py'
29--- lib/lp/translations/model/pofile.py 2010-01-14 16:39:18 +0000
30+++ lib/lp/translations/model/pofile.py 2010-03-10 18:38:19 +0000
31@@ -378,8 +378,7 @@
32 Orders the result by TranslationTemplateItem.sequence which must
33 be among `origin_tables`.
34 """
35- store = getUtility(IStoreSelector).get(MAIN_STORE, MASTER_FLAVOR)
36- results = store.using(origin_tables).find(
37+ results = Store.of(self).using(origin_tables).find(
38 POTMsgSet, SQL(query))
39 return results.order_by(TranslationTemplateItem.sequence)
40
41@@ -609,13 +608,6 @@
42 def translated(self):
43 """See `IPOFile`."""
44 raise NotImplementedError
45- # return iter(TranslationMessage.select('''
46- # POMsgSet.pofile = %d AND
47- # POMsgSet.iscomplete=TRUE AND
48- # POMsgSet.potmsgset = POTMsgSet.id AND
49- # POTMsgSet.sequence > 0''' % self.id,
50- # clauseTables = ['POMsgSet']
51- # ))
52
53 def untranslated(self):
54 """See `IPOFile`."""
55@@ -963,7 +955,7 @@
56 if self.potemplate.messageCount() > 0:
57 total = self.potemplate.messageCount()
58 else:
59- total = self.potemplate.getPOTMsgSets().count()
60+ total = self.potemplate.getPOTMsgSetsCount()
61 self.potemplate.messagecount = total
62
63 # Get number of translations done only in Launchpad.
64
65=== modified file 'lib/lp/translations/model/potemplate.py'
66--- lib/lp/translations/model/potemplate.py 2010-01-12 21:29:03 +0000
67+++ lib/lp/translations/model/potemplate.py 2010-03-10 18:38:19 +0000
68@@ -326,13 +326,10 @@
69
70 @property
71 def language_count(self):
72- return Language.select('''
73- POFile.language = Language.id AND
74- POFile.currentcount + POFile.rosettacount > 0 AND
75- POFile.potemplate = %s
76- ''' % sqlvalues(self.id),
77- clauseTables=['POFile'],
78- distinct=True).count()
79+ return Store.of(self).find(
80+ POFile,
81+ POFile.potemplate == self,
82+ POFile.rosettacount > 0).count()
83
84 @property
85 def translationtarget(self):
86@@ -442,8 +439,10 @@
87
88 def getPOTMsgSetsCount(self, current=True):
89 """See `IPOTemplate`."""
90- results = self.getPOTMsgSets(current, prefetch=False)
91- return results.count()
92+ clauses = (TranslationTemplateItem.potmsgset == self)
93+ if current:
94+ clauses = And(clauses, TranslationTemplateItem.sequence > 0)
95+ return Store.of(self).find(TranslationTemplateItem, clauses).count()
96
97 def getPOTMsgSetByID(self, id):
98 """See `IPOTemplate`."""
99
100=== modified file 'lib/lp/translations/templates/object-templates.pt'
101--- lib/lp/translations/templates/object-templates.pt 2010-02-15 16:00:01 +0000
102+++ lib/lp/translations/templates/object-templates.pt 2010-03-10 18:38:19 +0000
103@@ -108,7 +108,7 @@
104 </tal:inactive>
105 </td>
106 <td class="length_column"
107- tal:content="template/getPOTMsgSetsCount">1777</td>
108+ tal:content="template/messageCount">1777</td>
109 <td class="languages_column"
110 tal:content="template/language_count">777</td>
111 <td class="lastupdate_column">