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.
Revision history for this message
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
=== modified file 'lib/lp/answers/browser/tests/test_questiontarget.py'
--- lib/lp/answers/browser/tests/test_questiontarget.py 2011-08-16 06:17:12 +0000
+++ lib/lp/answers/browser/tests/test_questiontarget.py 2011-10-17 07:52:24 +0000
@@ -10,7 +10,9 @@
10from urllib import quote10from urllib import quote
1111
12from BeautifulSoup import BeautifulSoup12from BeautifulSoup import BeautifulSoup
13from storm.store import Store
13from zope.component import getUtility14from zope.component import getUtility
15from zope.security.proxy import removeSecurityProxy
14from zope.traversing.browser import absoluteURL16from zope.traversing.browser import absoluteURL
1517
16from lazr.restful.interfaces import (18from lazr.restful.interfaces import (
@@ -34,6 +36,7 @@
34 person_logged_in,36 person_logged_in,
35 TestCaseWithFactory,37 TestCaseWithFactory,
36 )38 )
39from lp.testing.matchers import BrowsesWithQueryLimit
37from lp.testing.sampledata import ADMIN_EMAIL40from lp.testing.sampledata import ADMIN_EMAIL
38from lp.testing.views import (41from lp.testing.views import (
39 create_initialized_view,42 create_initialized_view,
@@ -64,6 +67,23 @@
64 # This must not raise UnicodeEncodeError.67 # This must not raise UnicodeEncodeError.
65 self.assertIn(encoded_string, view.matching_faqs_url)68 self.assertIn(encoded_string, view.matching_faqs_url)
6669
70 def test_query_count(self):
71 # SearchQuestionsView does not query for the target SPN every time.
72 owner = self.factory.makePerson()
73 distro = self.factory.makeDistribution()
74 removeSecurityProxy(distro).official_answers = True
75 dsp = self.factory.makeDistributionSourcePackage(
76 distribution=distro)
77 questions = []
78 for i in range(0, 5):
79 questions.append(self.factory.makeQuestion(
80 target=dsp, owner=owner))
81 # Empty the cache.
82 Store.of(questions[0]).invalidate()
83 browses_under_limit = BrowsesWithQueryLimit(
84 31, owner, view_name="+questions")
85 self.assertThat(dsp, browses_under_limit)
86
6787
68class TestSearchQuestionsViewCanConfigureAnswers(TestCaseWithFactory):88class TestSearchQuestionsViewCanConfigureAnswers(TestCaseWithFactory):
6989
7090
=== modified file 'lib/lp/answers/model/question.py'
--- lib/lp/answers/model/question.py 2011-08-16 01:54:08 +0000
+++ lib/lp/answers/model/question.py 2011-10-17 07:52:24 +0000
@@ -1,8 +1,6 @@
1# Copyright 2009-2010 Canonical Ltd. This software is licensed under the1# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4# pylint: disable-msg=E0611,W0212
5
6"""Question models."""4"""Question models."""
75
8__metaclass__ = type6__metaclass__ = type
@@ -225,8 +223,7 @@
225 if self.product:223 if self.product:
226 return self.product224 return self.product
227 elif self.sourcepackagename:225 elif self.sourcepackagename:
228 return self.distribution.getSourcePackage(226 return self.distribution.getSourcePackage(self.sourcepackagename)
229 self.sourcepackagename.name)
230 else:227 else:
231 return self.distribution228 return self.distribution
232229