Merge lp:~wallyworld/launchpad/translator-licence-checks-531720 into lp:launchpad

Proposed by Ian Booth on 2012-10-19
Status: Merged
Approved by: Ian Booth on 2012-10-19
Approved revision: no longer in the source branch.
Merged at revision: 16171
Proposed branch: lp:~wallyworld/launchpad/translator-licence-checks-531720
Merge into: lp:launchpad
Diff against target: 82 lines (+15/-6)
2 files modified
lib/lp/translations/browser/pofile.py (+5/-5)
lib/lp/translations/model/translationsperson.py (+10/-1)
To merge this branch: bzr merge lp:~wallyworld/launchpad/translator-licence-checks-531720
Reviewer Review Type Date Requested Status
William Grant code 2012-10-19 Approve on 2012-10-19
Review via email: mp+130458@code.launchpad.net

Commit Message

Add caching to some translations views.

Description of the Change

== Implementation ==

Add caching for the model TranslationsPerson translations_relicensing_agreement property.
I also found repeated calls from the TAL to some other properties on the POFileView which I cached.

== Tests ==

Internal changes - existing tests suffice.

== Lint ==

Linting changed files:
  lib/lp/translations/browser/pofile.py
  lib/lp/translations/model/translationsperson.py

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/translations/browser/pofile.py'
2--- lib/lp/translations/browser/pofile.py 2012-02-15 21:14:05 +0000
3+++ lib/lp/translations/browser/pofile.py 2012-10-19 00:46:22 +0000
4@@ -275,22 +275,22 @@
5 def contributors(self):
6 return list(self.context.contributors)
7
8- @property
9+ @cachedproperty
10 def user_can_edit(self):
11 """Does the user have full edit rights for this translation?"""
12 return self.context.canEditTranslations(self.user)
13
14- @property
15+ @cachedproperty
16 def user_can_suggest(self):
17 """Is the user allowed to make suggestions here?"""
18 return self.context.canAddSuggestions(self.user)
19
20- @property
21+ @cachedproperty
22 def has_translationgroup(self):
23 """Is there a translation group for this translation?"""
24 return self.context.potemplate.translationgroups
25
26- @property
27+ @cachedproperty
28 def is_managed(self):
29 """Is a translation group member assigned to this translation?"""
30 for group in self.context.potemplate.translationgroups:
31@@ -298,7 +298,7 @@
32 return True
33 return False
34
35- @property
36+ @cachedproperty
37 def managers(self):
38 """List translation groups and translation teams for this translation.
39
40
41=== modified file 'lib/lp/translations/model/translationsperson.py'
42--- lib/lp/translations/model/translationsperson.py 2012-05-24 20:25:54 +0000
43+++ lib/lp/translations/model/translationsperson.py 2012-10-19 00:46:22 +0000
44@@ -32,6 +32,10 @@
45 from lp.registry.model.projectgroup import ProjectGroup
46 from lp.registry.model.teammembership import TeamParticipation
47 from lp.services.database.sqlbase import sqlvalues
48+from lp.services.propertycache import (
49+ cachedproperty,
50+ get_property_cache,
51+ )
52 from lp.services.worlddata.model.language import Language
53 from lp.translations.enums import TranslationPermission
54 from lp.translations.interfaces.translationgroup import ITranslationGroupSet
55@@ -95,7 +99,8 @@
56 """See `ITranslationsPerson`."""
57 return getUtility(ITranslatorSet).getByTranslator(self.person)
58
59- def get_translations_relicensing_agreement(self):
60+ @cachedproperty
61+ def _translations_relicensing_agreement(self):
62 """Return whether translator agrees to relicense their translations.
63
64 If she has made no explicit decision yet, return None.
65@@ -107,6 +112,9 @@
66 else:
67 return relicensing_agreement.allow_relicensing
68
69+ def get_translations_relicensing_agreement(self):
70+ return self._translations_relicensing_agreement
71+
72 def set_translations_relicensing_agreement(self, value):
73 """Set a translations relicensing decision by translator.
74
75@@ -120,6 +128,7 @@
76 allow_relicensing=value)
77 else:
78 relicensing_agreement.allow_relicensing = value
79+ del get_property_cache(self)._translations_relicensing_agreement
80
81 translations_relicensing_agreement = property(
82 get_translations_relicensing_agreement,