← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~mbp/launchpad/866100-affectsme-timeout into lp:launchpad

 

Martin Pool has proposed merging lp:~mbp/launchpad/866100-affectsme-timeout into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #866100 in Launchpad itself: "bug search with affects_me=on times out"
  https://bugs.launchpad.net/launchpad/+bug/866100

For more details, see:
https://code.launchpad.net/~mbp/launchpad/866100-affectsme-timeout/+merge/78806

This attempts to fix bug 866100 by changing the query from one that does an in-subquery to a simple join.  It's hard to be sure this will work, but it looks like it will help.
-- 
https://code.launchpad.net/~mbp/launchpad/866100-affectsme-timeout/+merge/78806
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~mbp/launchpad/866100-affectsme-timeout into lp:launchpad.
=== modified file 'lib/lp/bugs/model/bugtask.py'
--- lib/lp/bugs/model/bugtask.py	2011-10-05 18:24:09 +0000
+++ lib/lp/bugs/model/bugtask.py	2011-10-10 09:21:25 +0000
@@ -1867,7 +1867,10 @@
             decorator to call on each returned row.
         """
         params = self._require_params(params)
-        from lp.bugs.model.bug import Bug
+        from lp.bugs.model.bug import (
+            Bug,
+            BugAffectsPerson,
+            )
         extra_clauses = ['Bug.id = BugTask.bug']
         clauseTables = [BugTask, Bug]
         join_tables = []
@@ -2152,15 +2155,12 @@
         if params.affects_me:
             params.affected_user = params.user
         if params.affected_user:
-            affected_user_clause = """
-            BugTask.id IN (
-                SELECT BugTask.id FROM BugTask, BugAffectsPerson
-                WHERE BugTask.bug = BugAffectsPerson.bug
-                AND BugAffectsPerson.person = %(affected_user)s
-                AND BugAffectsPerson.affected = TRUE
-            )
-            """ % sqlvalues(affected_user=params.affected_user)
-            extra_clauses.append(affected_user_clause)
+            join_tables.append(
+                (BugAffectsPerson, Join(
+                    BugAffectsPerson, And(
+                        BugTask.bugID == BugAffectsPerson.bugID,
+                        BugAffectsPerson.affected,
+                        BugAffectsPerson.person == params.affected_user))))
 
         if params.nominated_for:
             mappings = sqlvalues(