Merge lp:~edwin-grubbs/launchpad/bug-577492-packaging-duplicates into lp:launchpad

Proposed by Edwin Grubbs
Status: Merged
Approved by: Edwin Grubbs
Approved revision: no longer in the source branch.
Merged at revision: 11266
Proposed branch: lp:~edwin-grubbs/launchpad/bug-577492-packaging-duplicates
Merge into: lp:launchpad
Diff against target: 80 lines (+29/-14)
2 files modified
lib/lp/registry/model/distroseries.py (+21/-13)
lib/lp/registry/tests/test_distroseries.py (+8/-1)
To merge this branch: bzr merge lp:~edwin-grubbs/launchpad/bug-577492-packaging-duplicates
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+31297@code.launchpad.net

Description of the change

Summary
-------

Eliminate duplicates on $distroseries/+packaging page.

Tests
-----

./bin/test -vv -m 'test_distroseries$'
./bin/test -vvt 'xx-show-distroseries-packaging.txt|doc/distroseries.txt'

Demo and Q/A
------------

* Open https://edge.launchpad.net/debian/squeeze/+packaging
  * Each sourcepackagename should only appear once in the list.

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Looks good. Q: should you be using the slave store instead of IStore(self)?

review: Approve (code)
Revision history for this message
Edwin Grubbs (edwin-grubbs) wrote :

> Looks good.  Q: should you be using the slave store instead of IStore(self)?

IStore() uses the default store, so it will use the slave store
automatically unless the user has made writes on launchpad recently,
in which case, using the master store is necessary to ensure that it
doesn't appear that the user's changes got reverted.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/registry/model/distroseries.py'
--- lib/lp/registry/model/distroseries.py 2010-07-27 20:59:06 +0000
+++ lib/lp/registry/model/distroseries.py 2010-07-29 15:23:22 +0000
@@ -356,28 +356,36 @@
356 # We join to SourcePackageName, ProductSeries, and Product to cache356 # We join to SourcePackageName, ProductSeries, and Product to cache
357 # the objects that are implcitly needed to work with a357 # the objects that are implcitly needed to work with a
358 # Packaging object.358 # Packaging object.
359 # Avoid circular import failures.
360 joins, conditions = self._current_sourcepackage_joins_and_conditions359 joins, conditions = self._current_sourcepackage_joins_and_conditions
361 origin = SQL(joins + """360 # XXX: EdwinGrubbs 2010-07-29 bug=374777
361 # Storm doesn't support DISTINCT ON.
362 origin = SQL('''
363 (
364 SELECT DISTINCT ON (Packaging.id)
365 Packaging.*,
366 spr.component AS spr_component,
367 SourcePackageName.name AS spn_name,
368 total_bug_heat,
369 po_messages
370 FROM %(joins)s
371 WHERE %(conditions)s
372 AND packaging.id IS NOT NULL
373 ) AS Packaging
362 JOIN ProductSeries374 JOIN ProductSeries
363 ON Packaging.productseries = ProductSeries.id375 ON Packaging.productseries = ProductSeries.id
364 JOIN Product376 JOIN Product
365 ON ProductSeries.product = Product.id377 ON ProductSeries.product = Product.id
366 """)378 ''' % dict(joins=joins, conditions=conditions))
367 condition = SQL(conditions + "AND packaging.id IS NOT NULL")379 return IStore(self).using(origin).find(Packaging).order_by('''
368 results = IStore(self).using(origin).find(Packaging, condition)380 (CASE WHEN spr_component = 1 THEN 1000 ELSE 0 END
369 return results.order_by("""
370 (
371 CASE WHEN spr.component = 1 THEN 1000 ELSE 0 END
372 + CASE WHEN Product.bugtracker IS NULL381 + CASE WHEN Product.bugtracker IS NULL
373 THEN coalesce(total_bug_heat, 10) ELSE 0 END382 THEN coalesce(total_bug_heat, 10) ELSE 0 END
374 + CASE WHEN ProductSeries.translations_autoimport_mode = 1383 + CASE WHEN ProductSeries.translations_autoimport_mode = 1
375 THEN coalesce(po_messages, 10) ELSE 0 END384 THEN coalesce(po_messages, 10) ELSE 0 END
376 + CASE WHEN ProductSeries.branch IS NULL THEN 500385 + CASE WHEN ProductSeries.branch IS NULL THEN 500 ELSE 0 END
377 ELSE 0 END386 ) DESC,
378 ) DESC,387 spn_name ASC
379 SourcePackageName.name ASC388 ''')
380 """)
381389
382 @property390 @property
383 def _current_sourcepackage_joins_and_conditions(self):391 def _current_sourcepackage_joins_and_conditions(self):
384392
=== modified file 'lib/lp/registry/tests/test_distroseries.py'
--- lib/lp/registry/tests/test_distroseries.py 2010-07-26 18:23:34 +0000
+++ lib/lp/registry/tests/test_distroseries.py 2010-07-29 15:23:22 +0000
@@ -211,7 +211,13 @@
211 self.universe_component = component_set['universe']211 self.universe_component = component_set['universe']
212 self.makeSeriesPackage('normal')212 self.makeSeriesPackage('normal')
213 self.makeSeriesPackage('translatable', messages=800)213 self.makeSeriesPackage('translatable', messages=800)
214 self.makeSeriesPackage('hot', heat=500)214 hot_package = self.makeSeriesPackage('hot', heat=500)
215 # Create a second SPPH for 'hot', to verify that duplicates are
216 # eliminated in the queries.
217 self.factory.makeSourcePackagePublishingHistory(
218 sourcepackagename=hot_package.sourcepackagename,
219 distroseries=self.series,
220 component=self.universe_component, section_name='web')
215 self.makeSeriesPackage('hot-translatable', heat=250, messages=1000)221 self.makeSeriesPackage('hot-translatable', heat=250, messages=1000)
216 self.makeSeriesPackage('main', is_main=True)222 self.makeSeriesPackage('main', is_main=True)
217 self.makeSeriesPackage('linked')223 self.makeSeriesPackage('linked')
@@ -247,6 +253,7 @@
247 owner=self.user)253 owner=self.user)
248 removeSecurityProxy(template).messagecount = messages254 removeSecurityProxy(template).messagecount = messages
249 self.packages[name] = source_package255 self.packages[name] = source_package
256 return source_package
250257
251 def linkPackage(self, name):258 def linkPackage(self, name):
252 product_series = self.factory.makeProductSeries()259 product_series = self.factory.makeProductSeries()