Merge lp:~cjwatson/launchpad/snap-git-url-optimise into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18291
Proposed branch: lp:~cjwatson/launchpad/snap-git-url-optimise
Merge into: lp:launchpad
Diff against target: 27 lines (+5/-4)
1 file modified
lib/lp/snappy/model/snap.py (+5/-4)
To merge this branch: bzr merge lp:~cjwatson/launchpad/snap-git-url-optimise
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+312512@code.launchpad.net

Commit message

Optimise slow query in SnapSet.findByURL.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
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/snappy/model/snap.py'
2--- lib/lp/snappy/model/snap.py 2016-12-02 12:53:41 +0000
3+++ lib/lp/snappy/model/snap.py 2016-12-06 00:03:32 +0000
4@@ -18,6 +18,7 @@
5 LeftJoin,
6 Not,
7 Or,
8+ Select,
9 )
10 from storm.locals import (
11 Bool,
12@@ -754,11 +755,11 @@
13 else:
14 visibility_clause = Or(
15 Snap.private == False,
16- And(
17- TeamParticipation.person == visible_by_user,
18- TeamParticipation.teamID == Snap.owner_id))
19+ Snap.owner_id.is_in(Select(
20+ TeamParticipation.teamID,
21+ TeamParticipation.person == visible_by_user)))
22 clauses.append(visibility_clause)
23- return IStore(Snap).find(Snap, *clauses).config(distinct=True)
24+ return IStore(Snap).find(Snap, *clauses)
25
26 def preloadDataForSnaps(self, snaps, user=None):
27 """See `ISnapSet`."""