launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #03645
[Merge] lp:~wgrant/launchpad/native-distinct-on into lp:launchpad
William Grant has proposed merging lp:~wgrant/launchpad/native-distinct-on into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~wgrant/launchpad/native-distinct-on/+merge/61199
Use a new Storm with support for DISTINCT ON. Replace the "DISTINCT ON (foo, bar) 0 as ignore" hack everywhere with this native support.
--
https://code.launchpad.net/~wgrant/launchpad/native-distinct-on/+merge/61199
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/native-distinct-on into lp:launchpad.
=== modified file 'lib/lp/bugs/model/bug.py'
--- lib/lp/bugs/model/bug.py 2011-05-16 18:06:29 +0000
+++ lib/lp/bugs/model/bug.py 2011-05-17 05:49:14 +0000
@@ -939,16 +939,13 @@
# subscribers.
return DecoratedResultSet(
IStore(BugSubscription).find(
- # XXX: GavinPanella 2010-09-17 bug=374777: This SQL(...) is a
- # hack; it does not seem to be possible to express DISTINCT ON
- # with Storm.
- (SQL("DISTINCT ON (BugSubscription.person) 0 AS ignore"),
- Person, BugSubscription),
+ (Person, BugSubscription),
Bug.duplicateof == self,
BugSubscription.bug_id == Bug.id,
BugSubscription.person_id == Person.id).order_by(
- BugSubscription.person_id),
- operator.itemgetter(2))
+ BugSubscription.person_id).config(
+ distinct=(BugSubscription.person_id,)),
+ operator.itemgetter(1))
def getSubscribersFromDuplicates(self, recipients=None, level=None):
"""See `IBug`.
@@ -976,7 +973,7 @@
recipients.addDupeSubscriber(
subscription.subscriber)
- unified_subscribers =(
+ unified_subscribers = (
info.duplicate_only_subscriptions.subscribers.union(
info.structural_subscriptions_from_duplicates.subscribers))
return unified_subscribers.sorted
@@ -991,20 +988,15 @@
self._unsubscribed_cache.add(person)
def cache_subscriber(row):
- _, subscriber, subscription = row
+ subscriber, subscription = row
if subscription.bug_id == self.id:
self._subscriber_cache.add(subscriber)
else:
self._subscriber_dups_cache.add(subscriber)
return subscriber
return DecoratedResultSet(Store.of(self).find(
- # XXX: RobertCollins 2010-09-22 bug=374777: This SQL(...) is a
- # hack; it does not seem to be possible to express DISTINCT ON
- # with Storm.
- (SQL("DISTINCT ON (Person.name, BugSubscription.person) "
- "0 AS ignore"),
# Return people and subscriptions
- Person, BugSubscription),
+ (Person, BugSubscription),
# For this bug or its duplicates
Or(
Bug.id == self.id,
@@ -1024,7 +1016,8 @@
# bug=https://bugs.launchpad.net/storm/+bug/627137
# RBC 20100831
SQL("""Person.id = TeamParticipation.team"""),
- ).order_by(Person.name),
+ ).order_by(Person.name).config(
+ distinct=(Person.name, BugSubscription.person_id)),
cache_subscriber, pre_iter_hook=cache_unsubscribed)
def getSubscriptionForPerson(self, person):
=== modified file 'lib/lp/registry/model/distroseries.py'
--- lib/lp/registry/model/distroseries.py 2011-05-10 13:53:16 +0000
+++ lib/lp/registry/model/distroseries.py 2011-05-17 05:49:14 +0000
@@ -468,8 +468,6 @@
translatable messages, and the source package release's component.
"""
find_spec = (
- SQL("DISTINCT ON (score, sourcepackagename.name) "
- "TRUE as _ignored"),
SourcePackageName,
SQL("""
coalesce(total_bug_heat, 0) + coalesce(po_messages, 0) +
@@ -524,9 +522,10 @@
condition = SQL("sourcepackagename.id = spn_info.sourcepackagename")
results = IStore(self).using(origin).find(find_spec, condition)
results = results.order_by('score DESC', SourcePackageName.name)
+ results = results.config(distinct=('score', SourcePackageName.name))
def decorator(row):
- _, spn, score, bug_count, total_messages = row
+ spn, score, bug_count, total_messages = row
return {
'package': SourcePackage(
sourcepackagename=spn, distroseries=self),
=== modified file 'lib/lp/registry/model/distroseriesdifference.py'
--- lib/lp/registry/model/distroseriesdifference.py 2011-05-12 21:33:10 +0000
+++ lib/lp/registry/model/distroseriesdifference.py 2011-05-17 05:49:14 +0000
@@ -100,11 +100,7 @@
:param in_parent: A boolean indicating if we should look in the parent
series' archive instead of the derived series' archive.
"""
- distinct_on = "DistroSeriesDifference.source_package_name"
columns = (
- # XXX: GavinPanella 2010-04-06 bug=374777: This SQL(...) is a hack; it
- # does not seem to be possible to express DISTINCT ON with Storm.
- SQL("DISTINCT ON (%s) 0 AS ignore" % distinct_on),
DistroSeriesDifference.source_package_name_id,
SourcePackagePublishingHistory,
)
@@ -149,9 +145,12 @@
DistroSeriesDifference.source_package_name_id,
Desc(SourcePackagePublishingHistory.id),
)
+ distinct_on = (
+ DistroSeriesDifference.source_package_name_id,
+ )
store = IStore(SourcePackagePublishingHistory)
- results = store.find(columns, conditions).order_by(*order_by)
- return DecoratedResultSet(results, itemgetter(1, 2))
+ return store.find(
+ columns, conditions).order_by(*order_by).config(distinct=distinct_on)
def most_recent_comments(dsds):
@@ -162,13 +161,7 @@
:param dsds: An iterable of `DistroSeriesDifference` instances.
"""
- distinct_on = storm_compile(
- DistroSeriesDifferenceComment.distro_series_difference_id)
columns = (
- # XXX: GavinPanella 2010-04-06 bug=374777: This SQL(...) is a
- # hack; it does not seem to be possible to express DISTINCT ON
- # with Storm.
- SQL("DISTINCT ON (%s) 0 AS ignore" % distinct_on),
DistroSeriesDifferenceComment,
Message,
)
@@ -180,9 +173,13 @@
DistroSeriesDifferenceComment.distro_series_difference_id,
Desc(DistroSeriesDifferenceComment.id),
)
+ distinct_on = (
+ DistroSeriesDifferenceComment.distro_series_difference_id,
+ )
store = IStore(DistroSeriesDifferenceComment)
- comments = store.find(columns, conditions).order_by(*order_by)
- return DecoratedResultSet(comments, itemgetter(1))
+ comments = store.find(
+ columns, conditions).order_by(*order_by).config(distinct=distinct_on)
+ return DecoratedResultSet(comments, itemgetter(0))
class DistroSeriesDifference(StormBase):
=== modified file 'lib/lp/soyuz/adapters/overrides.py'
--- lib/lp/soyuz/adapters/overrides.py 2011-05-13 08:27:42 +0000
+++ lib/lp/soyuz/adapters/overrides.py 2011-05-17 05:49:14 +0000
@@ -62,15 +62,13 @@
def calculateSourceOverrides(self, archive, distroseries, pocket, spns):
store = IStore(SourcePackagePublishingHistory)
def eager_load(rows):
- bulk.load(Component, (row[2] for row in rows))
- bulk.load(Section, (row[3] for row in rows))
+ bulk.load(Component, (row[1] for row in rows))
+ bulk.load(Section, (row[2] for row in rows))
already_published = DecoratedResultSet(
store.find(
- (SQL("""DISTINCT ON (
- SourcePackageRelease.sourcepackagename) 0 AS ignore"""),
- SourcePackageRelease.sourcepackagenameID,
- SourcePackagePublishingHistory.componentID,
- SourcePackagePublishingHistory.sectionID),
+ (SourcePackageRelease.sourcepackagenameID,
+ SourcePackagePublishingHistory.componentID,
+ SourcePackagePublishingHistory.sectionID),
SourcePackagePublishingHistory.pocket == pocket,
SourcePackagePublishingHistory.archiveID == archive.id,
SourcePackagePublishingHistory.distroseriesID ==
@@ -83,9 +81,10 @@
spn.id for spn in spns)).order_by(
SourcePackageRelease.sourcepackagenameID,
Desc(SourcePackagePublishingHistory.datecreated),
- Desc(SourcePackagePublishingHistory.id)),
- id_resolver(
- (SourcePackageName, Component, Section), slice(1, None)),
+ Desc(SourcePackagePublishingHistory.id),
+ ).config(
+ distinct=(SourcePackageRelease.sourcepackagenameID,)),
+ id_resolver((SourcePackageName, Component, Section)),
pre_iter_hook=eager_load)
return list(already_published)
@@ -93,23 +92,19 @@
binaries):
store = IStore(BinaryPackagePublishingHistory)
def eager_load(rows):
- bulk.load(Component, (row[3] for row in rows))
- bulk.load(Section, (row[4] for row in rows))
+ bulk.load(Component, (row[2] for row in rows))
+ bulk.load(Section, (row[3] for row in rows))
expanded = calculate_target_das(distroseries, binaries)
candidates = (
make_package_condition(archive, das, bpn)
for bpn, das in expanded)
already_published = DecoratedResultSet(
store.find(
- (SQL("""DISTINCT ON (
- BinaryPackagePublishingHistory.distroarchseries,
- BinaryPackageRelease.binarypackagename) 0
- AS ignore"""),
- BinaryPackageRelease.binarypackagenameID,
- BinaryPackagePublishingHistory.distroarchseriesID,
- BinaryPackagePublishingHistory.componentID,
- BinaryPackagePublishingHistory.sectionID,
- BinaryPackagePublishingHistory.priority),
+ (BinaryPackageRelease.binarypackagenameID,
+ BinaryPackagePublishingHistory.distroarchseriesID,
+ BinaryPackagePublishingHistory.componentID,
+ BinaryPackagePublishingHistory.sectionID,
+ BinaryPackagePublishingHistory.priority),
BinaryPackagePublishingHistory.pocket == pocket,
BinaryPackagePublishingHistory.status.is_in(
active_publishing_status),
@@ -119,11 +114,15 @@
BinaryPackagePublishingHistory.distroarchseriesID,
BinaryPackageRelease.binarypackagenameID,
Desc(BinaryPackagePublishingHistory.datecreated),
- Desc(BinaryPackagePublishingHistory.id)),
+ Desc(BinaryPackagePublishingHistory.id),
+ ).config(distinct=(
+ BinaryPackagePublishingHistory.distroarchseriesID,
+ BinaryPackageRelease.binarypackagenameID,
+ )
+ ),
id_resolver(
(BinaryPackageName, DistroArchSeries, Component, Section,
- None),
- slice(1, None)),
+ None)),
pre_iter_hook=eager_load)
return list(already_published)
@@ -206,10 +205,10 @@
BinaryPackageRelease.binarypackagenameID == bpn.id)
-def id_resolver(lookups, slice):
+def id_resolver(lookups):
def _resolve(row):
store = IStore(SourcePackagePublishingHistory)
return tuple(
(value if cls is None else store.get(cls, value))
- for value, cls in zip(row[slice], lookups))
+ for value, cls in zip(row, lookups))
return _resolve
=== modified file 'versions.cfg'
--- versions.cfg 2011-04-20 02:37:00 +0000
+++ versions.cfg 2011-05-17 05:49:14 +0000
@@ -72,7 +72,7 @@
Sphinx = 1.0.7
soupmatchers = 0.1r53
sourcecodegen = 0.6.9
-storm = 0.18.0.99-lpwithnodatetime-r392
+storm = 0.18.0.99-lpwithnodatetime-r393
testtools = 0.9.10
transaction = 1.0.0
Twisted = 11.0.0