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
1=== modified file 'lib/lp/registry/model/distroseries.py'
2--- lib/lp/registry/model/distroseries.py 2010-07-27 20:59:06 +0000
3+++ lib/lp/registry/model/distroseries.py 2010-07-29 15:23:22 +0000
4@@ -356,28 +356,36 @@
5 # We join to SourcePackageName, ProductSeries, and Product to cache
6 # the objects that are implcitly needed to work with a
7 # Packaging object.
8- # Avoid circular import failures.
9 joins, conditions = self._current_sourcepackage_joins_and_conditions
10- origin = SQL(joins + """
11+ # XXX: EdwinGrubbs 2010-07-29 bug=374777
12+ # Storm doesn't support DISTINCT ON.
13+ origin = SQL('''
14+ (
15+ SELECT DISTINCT ON (Packaging.id)
16+ Packaging.*,
17+ spr.component AS spr_component,
18+ SourcePackageName.name AS spn_name,
19+ total_bug_heat,
20+ po_messages
21+ FROM %(joins)s
22+ WHERE %(conditions)s
23+ AND packaging.id IS NOT NULL
24+ ) AS Packaging
25 JOIN ProductSeries
26 ON Packaging.productseries = ProductSeries.id
27 JOIN Product
28 ON ProductSeries.product = Product.id
29- """)
30- condition = SQL(conditions + "AND packaging.id IS NOT NULL")
31- results = IStore(self).using(origin).find(Packaging, condition)
32- return results.order_by("""
33- (
34- CASE WHEN spr.component = 1 THEN 1000 ELSE 0 END
35+ ''' % dict(joins=joins, conditions=conditions))
36+ return IStore(self).using(origin).find(Packaging).order_by('''
37+ (CASE WHEN spr_component = 1 THEN 1000 ELSE 0 END
38 + CASE WHEN Product.bugtracker IS NULL
39 THEN coalesce(total_bug_heat, 10) ELSE 0 END
40 + CASE WHEN ProductSeries.translations_autoimport_mode = 1
41 THEN coalesce(po_messages, 10) ELSE 0 END
42- + CASE WHEN ProductSeries.branch IS NULL THEN 500
43- ELSE 0 END
44- ) DESC,
45- SourcePackageName.name ASC
46- """)
47+ + CASE WHEN ProductSeries.branch IS NULL THEN 500 ELSE 0 END
48+ ) DESC,
49+ spn_name ASC
50+ ''')
51
52 @property
53 def _current_sourcepackage_joins_and_conditions(self):
54
55=== modified file 'lib/lp/registry/tests/test_distroseries.py'
56--- lib/lp/registry/tests/test_distroseries.py 2010-07-26 18:23:34 +0000
57+++ lib/lp/registry/tests/test_distroseries.py 2010-07-29 15:23:22 +0000
58@@ -211,7 +211,13 @@
59 self.universe_component = component_set['universe']
60 self.makeSeriesPackage('normal')
61 self.makeSeriesPackage('translatable', messages=800)
62- self.makeSeriesPackage('hot', heat=500)
63+ hot_package = self.makeSeriesPackage('hot', heat=500)
64+ # Create a second SPPH for 'hot', to verify that duplicates are
65+ # eliminated in the queries.
66+ self.factory.makeSourcePackagePublishingHistory(
67+ sourcepackagename=hot_package.sourcepackagename,
68+ distroseries=self.series,
69+ component=self.universe_component, section_name='web')
70 self.makeSeriesPackage('hot-translatable', heat=250, messages=1000)
71 self.makeSeriesPackage('main', is_main=True)
72 self.makeSeriesPackage('linked')
73@@ -247,6 +253,7 @@
74 owner=self.user)
75 removeSecurityProxy(template).messagecount = messages
76 self.packages[name] = source_package
77+ return source_package
78
79 def linkPackage(self, name):
80 product_series = self.factory.makeProductSeries()