Merge lp:~julian-edwards/launchpad/builder-history-timeout-bug-631206 into lp:launchpad

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: no longer in the source branch.
Merged at revision: 12375
Proposed branch: lp:~julian-edwards/launchpad/builder-history-timeout-bug-631206
Merge into: lp:launchpad
Diff against target: 98 lines (+50/-13)
1 file modified
lib/lp/buildmaster/model/buildfarmjob.py (+50/-13)
To merge this branch: bzr merge lp:~julian-edwards/launchpad/builder-history-timeout-bug-631206
Reviewer Review Type Date Requested Status
Abel Deuring (community) code Approve
Review via email: mp+49374@code.launchpad.net

Commit message

[r=adeuring][bug=631206] Make Builder:+history load in 2 seconds instead of timing out.

Description of the change

This change optimises the query that is in BuildFarmJobSet.getBuildsForBuilder(). See the bug for more commentary that I won't repeat here. Suffice to say that the page now renders inside 2 seconds instead of timing out fairly consistently for some builders/users combos.

bin/test -cvvt test_getBuildsForBuilder

To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) wrote :

nice work!

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/buildmaster/model/buildfarmjob.py'
2--- lib/lp/buildmaster/model/buildfarmjob.py 2010-10-04 21:44:32 +0000
3+++ lib/lp/buildmaster/model/buildfarmjob.py 2011-02-14 10:20:55 +0000
4@@ -15,10 +15,12 @@
5 from lazr.delegates import delegates
6 import pytz
7 from storm.expr import (
8- Coalesce,
9+ And,
10 Desc,
11 LeftJoin,
12 Or,
13+ Select,
14+ Union,
15 )
16 from storm.locals import (
17 Bool,
18@@ -400,19 +402,55 @@
19 # Currently only package builds can be private (via their
20 # related archive), but not all build farm jobs will have a
21 # related package build - hence the left join.
22- origin = [BuildFarmJob]
23- left_join_archive = [
24+ origin = [
25+ BuildFarmJob,
26 LeftJoin(
27 PackageBuild,
28 PackageBuild.build_farm_job == BuildFarmJob.id),
29- LeftJoin(
30- Archive, PackageBuild.archive == Archive.id),
31 ]
32
33+ # STORM syntax has totally obfuscated this query and wasted
34+ # THREE hours of my time converting perfectly good SQL syntax. I'm
35+ # really sorry if you're the poor sap who has to maintain this.
36+
37+ inner_privacy_query = (
38+ Union(
39+ Select(
40+ Archive.id,
41+ tables=(Archive,),
42+ where=(Archive.private == False)
43+ ),
44+ Select(
45+ Archive.id,
46+ tables=(Archive,),
47+ where=And(
48+ Archive.private == True,
49+ Archive.ownerID.is_in(
50+ Select(
51+ TeamParticipation.teamID,
52+ where=(TeamParticipation.person == user),
53+ distinct=True
54+ )
55+ )
56+ )
57+ )
58+ )
59+ )
60+
61 if user is None:
62 # Anonymous requests don't get to see private builds at all.
63- origin.extend(left_join_archive)
64- extra_clauses.append(Coalesce(Archive.private, False) == False)
65+ extra_clauses.append(
66+ Or(
67+ PackageBuild.id == None,
68+ PackageBuild.archive_id.is_in(
69+ Select(
70+ Archive.id,
71+ tables=(Archive,),
72+ where=(Archive.private == False)
73+ )
74+ )
75+ )
76+ )
77
78 elif user.inTeam(getUtility(ILaunchpadCelebrities).admin):
79 # Admins get to see everything.
80@@ -420,13 +458,12 @@
81 else:
82 # Everyone else sees all public builds and the
83 # specific private builds to which they have access.
84- origin.extend(left_join_archive)
85- origin.append(LeftJoin(
86- TeamParticipation,
87- TeamParticipation.teamID == Archive.ownerID))
88 extra_clauses.append(
89- Or(Coalesce(Archive.private, False) == False,
90- TeamParticipation.person == user))
91+ Or(
92+ PackageBuild.id == None,
93+ PackageBuild.archive_id.is_in(inner_privacy_query)
94+ )
95+ )
96
97 filtered_builds = IStore(BuildFarmJob).using(*origin).find(
98 BuildFarmJob, *extra_clauses)