← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~julian-edwards/launchpad/timeout-das-bug-618395 into lp:launchpad

 

Julian Edwards has proposed merging lp:~julian-edwards/launchpad/timeout-das-bug-618395 into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  #618395 DistroArchSeries:+index timing out ~ 7% of the time
  https://bugs.launchpad.net/bugs/618395

For more details, see:
https://code.launchpad.net/~julian-edwards/launchpad/timeout-das-bug-618395/+merge/47318

Fix timeouts in the distro arch series page.

1. Cache the view/batchnav property so it's not instantiated each time the template uses it.
2. Remove the FTI stuff when the input search text is blank since PSQL doesn't optimise that out automatically.
-- 
https://code.launchpad.net/~julian-edwards/launchpad/timeout-das-bug-618395/+merge/47318
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~julian-edwards/launchpad/timeout-das-bug-618395 into lp:launchpad.
=== modified file 'lib/lp/soyuz/browser/packagesearch.py'
--- lib/lp/soyuz/browser/packagesearch.py	2010-08-24 10:45:57 +0000
+++ lib/lp/soyuz/browser/packagesearch.py	2011-01-24 21:28:16 +0000
@@ -29,14 +29,14 @@
     @cachedproperty
     def matches(self):
         """Return the number of matched search results."""
-        return self.search_results.count()
+        return self.batchnav.batch.total()
 
     @property
     def detailed(self):
         """Return whether detailed results should be provided."""
         return self.matches <= 5
 
-    @property
+    @cachedproperty
     def batchnav(self):
         """Return the batch navigator for the search results."""
         return BatchNavigator(self.search_results, self.request)

=== modified file 'lib/lp/soyuz/model/distroarchseries.py'
--- lib/lp/soyuz/model/distroarchseries.py	2010-12-24 02:22:11 +0000
+++ lib/lp/soyuz/model/distroarchseries.py	2011-01-24 21:28:16 +0000
@@ -192,30 +192,41 @@
                     BinaryPackageName.id
                 )
             ]
-        find_spec = (
-            BinaryPackageRelease,
-            BinaryPackageName,
-            SQL("rank(BinaryPackageRelease.fti, ftq(%s)) AS rank" %
-                sqlvalues(text))
-            )
+        if text:
+            find_spec = (
+                BinaryPackageRelease,
+                BinaryPackageName,
+                SQL("rank(BinaryPackageRelease.fti, ftq(%s)) AS rank" %
+                    sqlvalues(text))
+                )
+        else:
+            find_spec = (
+                BinaryPackageRelease,
+                BinaryPackageName,
+                BinaryPackageName, # dummy value
+                )
         archives = self.distroseries.distribution.getArchiveIDList()
 
         # Note: When attempting to convert the query below into straight
         # Storm expressions, a 'tuple index out-of-range' error was always
         # raised.
+        query = """
+            BinaryPackagePublishingHistory.distroarchseries = %s AND
+            BinaryPackagePublishingHistory.archive IN %s AND
+            BinaryPackagePublishingHistory.dateremoved is NULL
+            """ % (quote(self), quote(archives))
+        if text:
+            query += """
+            AND (BinaryPackageRelease.fti @@ ftq(%s) OR
+            BinaryPackageName.name ILIKE '%%' || %s || '%%')
+            """ % (quote(text), quote_like(text))
         result = store.using(*origin).find(
-            find_spec,
-            """
-            BinaryPackagePublishingHistory.distroarchseries = %s AND
-            BinaryPackagePublishingHistory.archive IN %s AND
-            BinaryPackagePublishingHistory.dateremoved is NULL AND
-            (BinaryPackageRelease.fti @@ ftq(%s) OR
-             BinaryPackageName.name ILIKE '%%' || %s || '%%')
-            """ % (quote(self), quote(archives),
-                   quote(text), quote_like(text))
-            ).config(distinct=True)
+            find_spec, query).config(distinct=True)
 
-        result = result.order_by("rank DESC, BinaryPackageName.name")
+        if text:
+            result = result.order_by("rank DESC, BinaryPackageName.name")
+        else:
+            result = result.order_by("BinaryPackageName.name")
 
         # import here to avoid circular import problems
         from lp.soyuz.model.distroarchseriesbinarypackagerelease import (


Follow ups