Merge lp:~rvb/launchpad/bugs-timeout-bug-892820 into lp:launchpad

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 14409
Proposed branch: lp:~rvb/launchpad/bugs-timeout-bug-892820
Merge into: lp:launchpad
Diff against target: 47 lines (+14/-17)
1 file modified
lib/lp/bugs/model/bugtask.py (+14/-17)
To merge this branch: bzr merge lp:~rvb/launchpad/bugs-timeout-bug-892820
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+83631@code.launchpad.net

Commit message

[r=benji][bug=892820] Avoid joins in a subquery to improve performance.

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

Looks good.

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/bugs/model/bugtask.py'
2--- lib/lp/bugs/model/bugtask.py 2011-11-28 00:54:24 +0000
3+++ lib/lp/bugs/model/bugtask.py 2011-11-28 16:10:21 +0000
4@@ -1375,7 +1375,7 @@
5 if role.in_admin:
6 return True
7
8- # Similar to admins, the Bug Watch Updater, Bug Importer and
9+ # Similar to admins, the Bug Watch Updater, Bug Importer and
10 # Janitor can always change bug details.
11 if (
12 role.in_bug_watch_updater or role.in_bug_importer or
13@@ -2213,22 +2213,19 @@
14 # is not for subscription to notifications.
15 # See bug #191809
16 if params.bug_supervisor:
17- bug_supervisor_clause = """BugTask.id IN (
18- SELECT BugTask.id FROM BugTask, Product
19- WHERE BugTask.product = Product.id
20- AND Product.bug_supervisor = %(bug_supervisor)s
21- UNION ALL
22- SELECT BugTask.id
23- FROM BugTask, StructuralSubscription
24- WHERE
25- BugTask.distribution = StructuralSubscription.distribution
26- AND BugTask.sourcepackagename =
27- StructuralSubscription.sourcepackagename
28- AND StructuralSubscription.subscriber = %(bug_supervisor)s
29- UNION ALL
30- SELECT BugTask.id FROM BugTask, Distribution
31- WHERE BugTask.distribution = Distribution.id
32- AND Distribution.bug_supervisor = %(bug_supervisor)s
33+ bug_supervisor_clause = """(
34+ BugTask.product IN (
35+ SELECT id FROM Product
36+ WHERE Product.bug_supervisor = %(bug_supervisor)s)
37+ OR
38+ ((BugTask.distribution, Bugtask.sourcepackagename) IN
39+ (SELECT distribution, sourcepackagename FROM
40+ StructuralSubscription
41+ WHERE subscriber = %(bug_supervisor)s))
42+ OR
43+ BugTask.distribution IN (
44+ SELECT id from Distribution WHERE
45+ Distribution.bug_supervisor = %(bug_supervisor)s)
46 )""" % sqlvalues(bug_supervisor=params.bug_supervisor)
47 extra_clauses.append(bug_supervisor_clause)
48