← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jtv/launchpad/cache-pofile-view-permissions into lp:launchpad

 

Jeroen T. Vermeulen has proposed merging lp:~jtv/launchpad/cache-pofile-view-permissions into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers): code
Related bugs:
  #297136 Many repeated queries for allow_relicensing on +translate pages
  https://bugs.launchpad.net/bugs/297136


= Bug 297136 =

This should strip a few dozen pointlessly repeated queries off the performance-critical POFile:+translate pages.  I came across the omissions while working on something else.  The queries don't cost that much time, but we'll often see around a hundred of them on a single request and there's just no good reason for that.

My branch effectively hoists a few very similar checks from the individual message views up into the surrounding POFile page view (if any).  The checks all depend on the relationship between the user and the POFile, and global system state.  Neither will ever differ between messages on the same translate page.

(There's also a very minor cleanup of list handling at the end).
-- 
https://code.launchpad.net/~jtv/launchpad/cache-pofile-view-permissions/+merge/41930
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/launchpad/cache-pofile-view-permissions into lp:launchpad.
=== modified file 'lib/lp/translations/browser/pofile.py'
--- lib/lp/translations/browser/pofile.py	2010-11-16 13:10:43 +0000
+++ lib/lp/translations/browser/pofile.py	2010-11-26 06:54:01 +0000
@@ -289,12 +289,12 @@
     def contributors(self):
         return tuple(self.context.contributors)
 
-    @property
+    @cachedproperty
     def user_can_edit(self):
         """Does the user have full edit rights for this translation?"""
         return self.context.canEditTranslations(self.user)
 
-    @property
+    @cachedproperty
     def user_can_suggest(self):
         """Is the user allowed to make suggestions here?"""
         return self.context.canAddSuggestions(self.user)
@@ -824,11 +824,11 @@
 
     def _buildTranslationMessageViews(self, for_potmsgsets):
         """Build translation message views for all potmsgsets given."""
+        can_edit = self.context.canEditTranslations(self.user)
         for potmsgset in for_potmsgsets:
             translationmessage = (
                 potmsgset.getCurrentTranslationMessageOrDummy(self.context))
             error = self.errors.get(potmsgset)
-            can_edit = self.context.canEditTranslations(self.user)
 
             view = self._prepareView(
                 CurrentTranslationMessageView, translationmessage,
@@ -985,7 +985,7 @@
     def _messages_html_id(self):
         order = []
         for message in self.translationmessage_views:
-            if (message.form_is_writeable):
+            if self.form_is_writeable:
                 for dictionary in message.translation_dictionaries:
                     order.append(
                         dictionary['html_id_translation'] + '_new')

=== modified file 'lib/lp/translations/browser/translationmessage.py'
--- lib/lp/translations/browser/translationmessage.py	2010-10-28 09:54:48 +0000
+++ lib/lp/translations/browser/translationmessage.py	2010-11-26 06:54:01 +0000
@@ -1236,14 +1236,12 @@
             alt_current = potmsgset.getCurrentTranslationMessage(
                 self.pofile.potemplate, self.sec_lang)
             if alt_current is not None:
-                alt_current.setPOFile(alt_pofile)
-            if alt_current is not None:
                 alt_submissions.append(alt_current)
             alt_external = list(
                 potmsgset.getExternallyUsedTranslationMessages(self.sec_lang))
-            for suggestion in alt_external:
+            alt_submissions.extend(alt_external)
+            for suggestion in alt_submissions:
                 suggestion.setPOFile(alt_pofile)
-            alt_submissions.extend(alt_external)
             alt_title = self.sec_lang.englishname
 
         # To maintain compatibility with the old DB model as much as possible,