Merge lp:~cjwatson/launchpad/dsp-vocab-distinct-dspc-name into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18191
Proposed branch: lp:~cjwatson/launchpad/dsp-vocab-distinct-dspc-name
Merge into: lp:launchpad
Diff against target: 57 lines (+24/-2)
2 files modified
lib/lp/registry/tests/test_distributionsourcepackage_vocabulary.py (+22/-1)
lib/lp/registry/vocabularies.py (+2/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/dsp-vocab-distinct-dspc-name
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+305601@code.launchpad.net

Commit message

Eliminate duplicate results from DistributionSourcePackageVocabulary searches.

Description of the change

Eliminate duplicate results from DistributionSourcePackageVocabulary searches.

I've tested the modified query on dogfood and confirmed that this makes negligible difference to run-time.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) wrote :

The unindexed sort already makes the plan as terrible as it can get.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/registry/tests/test_distributionsourcepackage_vocabulary.py'
--- lib/lp/registry/tests/test_distributionsourcepackage_vocabulary.py 2016-07-27 17:19:20 +0000
+++ lib/lp/registry/tests/test_distributionsourcepackage_vocabulary.py 2016-09-13 13:24:43 +0000
@@ -5,10 +5,14 @@
55
6__metaclass__ = type6__metaclass__ = type
77
8from lp.registry.interfaces.pocket import PackagePublishingPocket
8from lp.registry.vocabularies import DistributionSourcePackageVocabulary9from lp.registry.vocabularies import DistributionSourcePackageVocabulary
9from lp.services.webapp.vocabulary import IHugeVocabulary10from lp.services.webapp.vocabulary import IHugeVocabulary
10from lp.soyuz.enums import ArchivePurpose11from lp.soyuz.enums import ArchivePurpose
11from lp.testing import TestCaseWithFactory12from lp.testing import (
13 person_logged_in,
14 TestCaseWithFactory,
15 )
12from lp.testing.layers import DatabaseFunctionalLayer16from lp.testing.layers import DatabaseFunctionalLayer
1317
1418
@@ -266,6 +270,23 @@
266 self.assertEqual('snarf-server', terms[2].token)270 self.assertEqual('snarf-server', terms[2].token)
267 self.assertEqual('pting-client', terms[3].token)271 self.assertEqual('pting-client', terms[3].token)
268272
273 def test_searchForTerms_deduplication(self):
274 # Search deduplicates cache rows with the same name, e.g. an
275 # official source package that also has an official branch.
276 distro = self.factory.makeDistribution(name='fnord')
277 distroseries = self.factory.makeDistroSeries(distribution=distro)
278 self.factory.makeDSPCache(
279 distroseries=distroseries, sourcepackagename='snarf')
280 branch = self.factory.makePackageBranch(distroseries=distroseries)
281 with person_logged_in(distro.owner):
282 distroseries.getSourcePackage('snarf').setBranch(
283 PackagePublishingPocket.RELEASE, branch, distro.owner)
284 vocabulary = DistributionSourcePackageVocabulary(distro)
285 results = vocabulary.searchForTerms(query='snarf')
286 terms = list(results)
287 self.assertEqual(1, len(terms))
288 self.assertEqual('snarf', terms[0].token)
289
269 def test_searchForTerms_partner_archive(self):290 def test_searchForTerms_partner_archive(self):
270 # Packages in partner archives are searched.291 # Packages in partner archives are searched.
271 distro = self.factory.makeDistribution(name='fnord')292 distro = self.factory.makeDistribution(name='fnord')
272293
=== modified file 'lib/lp/registry/vocabularies.py'
--- lib/lp/registry/vocabularies.py 2016-07-27 17:19:20 +0000
+++ lib/lp/registry/vocabularies.py 2016-09-13 13:24:43 +0000
@@ -2141,7 +2141,8 @@
2141 DistributionSourcePackageCache.distribution ==2141 DistributionSourcePackageCache.distribution ==
2142 self.distribution,2142 self.distribution,
2143 ),2143 ),
2144 tables=DistributionSourcePackageCache))2144 tables=DistributionSourcePackageCache,
2145 distinct=(DistributionSourcePackageCache.name,)))
2145 SearchableDSPC = Table("SearchableDSPC")2146 SearchableDSPC = Table("SearchableDSPC")
2146 searchable_dspc_name = Column("name", SearchableDSPC)2147 searchable_dspc_name = Column("name", SearchableDSPC)
2147 searchable_dspc_sourcepackagename = Column(2148 searchable_dspc_sourcepackagename = Column(