Code review comment for lp:~michael.nelson/launchpad/616331-private-builds-in-builder-history

Revision history for this message
Michael Nelson (michael.nelson) wrote :

On Wed, Aug 11, 2010 at 7:54 PM, Edwin Grubbs
<email address hidden> wrote:
> Review: Approve code
> Hi Michael,
>
> This is a nice improvement. Since the TeamParticipation table won't be used if the user is anonymous or an admin, it would be a small but easy optimization to not join it into those queries. For example:
>
> origin = [
>  BuildFarmJob,
>  LeftJoin(PackageBuild, ...),
>  LeftJoin(Archive, ...),
>  ]
>
> if ANONYMOUS:
>  ...
> elif ADMIN:
>  ...
> else:
>  origin.append(LeftJoin(TeamParticipation, ...))
>
> filtered_builds = IStore(BuildFarmJob).using(*origin).find(...)
>
> I guess if an admin is running the query, there is no reason to use any tables besides BuildFarmJob.

Yes... good point. I've attached an incremental (pushed as r9651) that
only uses the joins when necessary. Thanks!

1=== modified file 'lib/lp/buildmaster/model/buildfarmjob.py'
2--- lib/lp/buildmaster/model/buildfarmjob.py 2010-08-11 17:09:45 +0000
3+++ lib/lp/buildmaster/model/buildfarmjob.py 2010-08-11 21:26:07 +0000
4@@ -365,15 +365,18 @@
5 # Currently only package builds can be private (via their
6 # related archive), but not all build farm jobs will have a
7 # related package build - hence the left join.
8- left_join_pkg_builds = LeftJoin(
9- PackageBuild, PackageBuild.build_farm_job == BuildFarmJob.id)
10- left_join_archive = LeftJoin(
11- Archive, PackageBuild.archive == Archive.id)
12- left_join_participation = LeftJoin(
13- TeamParticipation, TeamParticipation.teamID == Archive.ownerID)
14+ origin = [BuildFarmJob]
15+ left_join_archive = [
16+ LeftJoin(
17+ PackageBuild,
18+ PackageBuild.build_farm_job == BuildFarmJob.id),
19+ LeftJoin(
20+ Archive, PackageBuild.archive == Archive.id),
21+ ]
22
23 if user is None:
24 # Anonymous requests don't get to see private builds at all.
25+ origin.extend(left_join_archive)
26 extra_clauses.append(Coalesce(Archive.private, False) == False)
27
28 elif user.inTeam(getUtility(ILaunchpadCelebrities).admin):
29@@ -382,16 +385,15 @@
30 else:
31 # Everyone else sees all public builds and the
32 # specific private builds to which they have access.
33+ origin.extend(left_join_archive)
34+ origin.append(LeftJoin(
35+ TeamParticipation, TeamParticipation.teamID == Archive.ownerID))
36 extra_clauses.append(
37 Or(Coalesce(Archive.private, False) == False,
38 TeamParticipation.person == user))
39
40- filtered_builds = IStore(BuildFarmJob).using(
41- BuildFarmJob,
42- left_join_pkg_builds,
43- left_join_archive,
44- left_join_participation,
45- ).find(BuildFarmJob, *extra_clauses)
46+ filtered_builds = IStore(BuildFarmJob).using(*origin).find(
47+ BuildFarmJob, *extra_clauses)
48
49 filtered_builds.order_by(
50 Desc(BuildFarmJob.date_finished), BuildFarmJob.id)

« Back to merge proposal