Merge lp:~stevenk/launchpad/dsp-questions-statement-death into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 14158
Proposed branch: lp:~stevenk/launchpad/dsp-questions-statement-death
Merge into: lp:launchpad
Diff against target: 68 lines (+22/-5)
2 files modified
lib/lp/answers/browser/tests/test_questiontarget.py (+20/-0)
lib/lp/answers/model/question.py (+2/-5)
To merge this branch: bzr merge lp:~stevenk/launchpad/dsp-questions-statement-death
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+79519@code.launchpad.net

Commit message

[r=lifeless][bug=876205] Stop IQuestion.target excessively querying for the SPN if the target is a DSP.

Description of the change

This branch is a little badly named, but it stops IQuestion.target querying for SourcePackageName.name (every time!) and then passing that into IDistribution.getSourcePackage().

To post a comment you must log in.
Robert Collins (lifeless) wrote :

hahahahaha

hahahahahhaahahahahah

hahahahahahahahaaha

ahhh.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/answers/browser/tests/test_questiontarget.py'
2--- lib/lp/answers/browser/tests/test_questiontarget.py 2011-08-16 06:17:12 +0000
3+++ lib/lp/answers/browser/tests/test_questiontarget.py 2011-10-17 07:52:24 +0000
4@@ -10,7 +10,9 @@
5 from urllib import quote
6
7 from BeautifulSoup import BeautifulSoup
8+from storm.store import Store
9 from zope.component import getUtility
10+from zope.security.proxy import removeSecurityProxy
11 from zope.traversing.browser import absoluteURL
12
13 from lazr.restful.interfaces import (
14@@ -34,6 +36,7 @@
15 person_logged_in,
16 TestCaseWithFactory,
17 )
18+from lp.testing.matchers import BrowsesWithQueryLimit
19 from lp.testing.sampledata import ADMIN_EMAIL
20 from lp.testing.views import (
21 create_initialized_view,
22@@ -64,6 +67,23 @@
23 # This must not raise UnicodeEncodeError.
24 self.assertIn(encoded_string, view.matching_faqs_url)
25
26+ def test_query_count(self):
27+ # SearchQuestionsView does not query for the target SPN every time.
28+ owner = self.factory.makePerson()
29+ distro = self.factory.makeDistribution()
30+ removeSecurityProxy(distro).official_answers = True
31+ dsp = self.factory.makeDistributionSourcePackage(
32+ distribution=distro)
33+ questions = []
34+ for i in range(0, 5):
35+ questions.append(self.factory.makeQuestion(
36+ target=dsp, owner=owner))
37+ # Empty the cache.
38+ Store.of(questions[0]).invalidate()
39+ browses_under_limit = BrowsesWithQueryLimit(
40+ 31, owner, view_name="+questions")
41+ self.assertThat(dsp, browses_under_limit)
42+
43
44 class TestSearchQuestionsViewCanConfigureAnswers(TestCaseWithFactory):
45
46
47=== modified file 'lib/lp/answers/model/question.py'
48--- lib/lp/answers/model/question.py 2011-08-16 01:54:08 +0000
49+++ lib/lp/answers/model/question.py 2011-10-17 07:52:24 +0000
50@@ -1,8 +1,6 @@
51-# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
52+# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
53 # GNU Affero General Public License version 3 (see the file LICENSE).
54
55-# pylint: disable-msg=E0611,W0212
56-
57 """Question models."""
58
59 __metaclass__ = type
60@@ -225,8 +223,7 @@
61 if self.product:
62 return self.product
63 elif self.sourcepackagename:
64- return self.distribution.getSourcePackage(
65- self.sourcepackagename.name)
66+ return self.distribution.getSourcePackage(self.sourcepackagename)
67 else:
68 return self.distribution
69