Merge lp:~cjwatson/launchpad/git-basic-browser into lp:launchpad

Proposed by Colin Watson on 2015-03-05
Status: Merged
Approved by: Colin Watson on 2015-03-05
Approved revision: no longer in the source branch.
Merged at revision: 17377
Proposed branch: lp:~cjwatson/launchpad/git-basic-browser
Merge into: lp:launchpad
Diff against target: 94 lines (+27/-9)
5 files modified
lib/lp/code/browser/tests/test_branch.py (+1/-1)
lib/lp/code/interfaces/gitlookup.py (+2/-2)
lib/lp/code/model/gitlookup.py (+7/-4)
lib/lp/code/model/tests/test_gitlookup.py (+14/-0)
lib/lp/registry/browser/person.py (+3/-2)
To merge this branch: bzr merge lp:~cjwatson/launchpad/git-basic-browser
Reviewer Review Type Date Requested Status
Colin Watson Approve on 2015-03-05
Review via email: mp+251911@code.launchpad.net

Commit message

Fix the query count for lp.code.browser.tests.test_branch.TestBranchView.test_query_count_index_with_subscribers.

Description of the change

Fix the query count for lp.code.browser.tests.test_branch.TestBranchView.test_query_count_index_with_subscribers. One of the queries is easily avoidable by passing the context IPerson down to IGitTraverse.traverse so that it doesn't have to look it up again; the other is an extra PillarName lookup and doesn't seem worth the effort to avoid.

To post a comment you must log in.
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/browser/tests/test_branch.py'
2--- lib/lp/code/browser/tests/test_branch.py 2014-12-06 10:45:17 +0000
3+++ lib/lp/code/browser/tests/test_branch.py 2015-03-05 11:45:47 +0000
4@@ -558,7 +558,7 @@
5 logout()
6 with StormStatementRecorder() as recorder:
7 browser.open(branch_url)
8- self.assertThat(recorder, HasQueryCount(Equals(26)))
9+ self.assertThat(recorder, HasQueryCount(Equals(27)))
10
11
12 class TestBranchViewPrivateArtifacts(BrowserTestCase):
13
14=== modified file 'lib/lp/code/interfaces/gitlookup.py'
15--- lib/lp/code/interfaces/gitlookup.py 2015-02-27 10:01:45 +0000
16+++ lib/lp/code/interfaces/gitlookup.py 2015-03-05 11:45:47 +0000
17@@ -33,9 +33,9 @@
18 class IGitTraverser(Interface):
19 """Utility for traversing to an object that can have a Git repository."""
20
21- def traverse(segments):
22+ def traverse(segments, owner=None):
23 """Traverse to the object referred to by a prefix of the 'segments'
24- iterable.
25+ iterable, starting from 'owner' if given.
26
27 :raises InvalidNamespace: If the path cannot be parsed as a
28 repository namespace.
29
30=== modified file 'lib/lp/code/model/gitlookup.py'
31--- lib/lp/code/model/gitlookup.py 2015-03-03 01:36:13 +0000
32+++ lib/lp/code/model/gitlookup.py 2015-03-05 11:45:47 +0000
33@@ -252,12 +252,15 @@
34
35 implements(IGitTraverser)
36
37- def traverse(self, segments):
38+ def traverse(self, segments, owner=None):
39 """See `IGitTraverser`."""
40- owner = None
41- target = None
42 repository = None
43- traversable = RootGitTraversable()
44+ if owner is None:
45+ target = None
46+ traversable = RootGitTraversable()
47+ else:
48+ target = owner
49+ traversable = adapt(owner, IGitTraversable)
50 segments_iter = SegmentIterator(segments)
51 while traversable is not None:
52 try:
53
54=== modified file 'lib/lp/code/model/tests/test_gitlookup.py'
55--- lib/lp/code/model/tests/test_gitlookup.py 2015-03-03 01:36:13 +0000
56+++ lib/lp/code/model/tests/test_gitlookup.py 2015-03-05 11:45:47 +0000
57@@ -453,3 +453,17 @@
58 person.name, dsp.distribution.name, dsp.sourcepackagename.name,
59 repository.name),
60 person, dsp, repository)
61+
62+ def test_person_repository_from_person(self):
63+ # To save on queries, `traverse` can be given a person as a starting
64+ # point for the traversal.
65+ person = self.factory.makePerson(name="person")
66+ repository = self.factory.makeGitRepository(
67+ owner=person, target=person, name=u"repository")
68+ segments = ["~person", "+git", "repository"]
69+ self.assertEqual(
70+ (person, person, repository),
71+ self.traverser.traverse(iter(segments)))
72+ self.assertEqual(
73+ (person, person, repository),
74+ self.traverser.traverse(iter(segments[1:]), owner=person))
75
76=== modified file 'lib/lp/registry/browser/person.py'
77--- lib/lp/registry/browser/person.py 2015-03-05 10:18:41 +0000
78+++ lib/lp/registry/browser/person.py 2015-03-05 11:45:47 +0000
79@@ -373,12 +373,13 @@
80 # the traversal stack immediately, as if we fail to find a Git
81 # repository we will need to look for a Bazaar branch instead.
82 segments = (
83- ["~%s" % self.context.name, pillar_name] +
84+ [pillar_name] +
85 list(reversed(self.request.getTraversalStack())))
86 num_segments = len(segments)
87 iter_segments = iter(segments)
88 traverser = getUtility(IGitTraverser)
89- _, target, repository = traverser.traverse(iter_segments)
90+ _, target, repository = traverser.traverse(
91+ iter_segments, owner=self.context)
92 if repository is None:
93 raise NotFoundError
94 for i in range(num_segments - len(list(iter_segments))):