← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/dsp-vocab-distinct-dspc-name into lp:launchpad.

Commit message:
Eliminate duplicate results from DistributionSourcePackageVocabulary searches.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/dsp-vocab-distinct-dspc-name/+merge/305601

Eliminate duplicate results from DistributionSourcePackageVocabulary searches.

I've tested the modified query on dogfood and confirmed that this makes negligible difference to run-time.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/dsp-vocab-distinct-dspc-name into lp:launchpad.
=== 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 @@
 
 __metaclass__ = type
 
+from lp.registry.interfaces.pocket import PackagePublishingPocket
 from lp.registry.vocabularies import DistributionSourcePackageVocabulary
 from lp.services.webapp.vocabulary import IHugeVocabulary
 from lp.soyuz.enums import ArchivePurpose
-from lp.testing import TestCaseWithFactory
+from lp.testing import (
+    person_logged_in,
+    TestCaseWithFactory,
+    )
 from lp.testing.layers import DatabaseFunctionalLayer
 
 
@@ -266,6 +270,23 @@
         self.assertEqual('snarf-server', terms[2].token)
         self.assertEqual('pting-client', terms[3].token)
 
+    def test_searchForTerms_deduplication(self):
+        # Search deduplicates cache rows with the same name, e.g. an
+        # official source package that also has an official branch.
+        distro = self.factory.makeDistribution(name='fnord')
+        distroseries = self.factory.makeDistroSeries(distribution=distro)
+        self.factory.makeDSPCache(
+            distroseries=distroseries, sourcepackagename='snarf')
+        branch = self.factory.makePackageBranch(distroseries=distroseries)
+        with person_logged_in(distro.owner):
+            distroseries.getSourcePackage('snarf').setBranch(
+                PackagePublishingPocket.RELEASE, branch, distro.owner)
+        vocabulary = DistributionSourcePackageVocabulary(distro)
+        results = vocabulary.searchForTerms(query='snarf')
+        terms = list(results)
+        self.assertEqual(1, len(terms))
+        self.assertEqual('snarf', terms[0].token)
+
     def test_searchForTerms_partner_archive(self):
         # Packages in partner archives are searched.
         distro = self.factory.makeDistribution(name='fnord')

=== 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 @@
                 DistributionSourcePackageCache.distribution ==
                     self.distribution,
                 ),
-            tables=DistributionSourcePackageCache))
+            tables=DistributionSourcePackageCache,
+            distinct=(DistributionSourcePackageCache.name,)))
         SearchableDSPC = Table("SearchableDSPC")
         searchable_dspc_name = Column("name", SearchableDSPC)
         searchable_dspc_sourcepackagename = Column(


References