Skip to content

Commit

Permalink
[#2034] apply distinct after union
Browse files Browse the repository at this point in the history
  • Loading branch information
wardi committed Nov 10, 2014
1 parent 272a428 commit c04c273
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ckan/model/activity.py
Expand Up @@ -80,17 +80,22 @@ def _activities_limit(q, limit, offset=None):
Return an SQLAlchemy query for all activities at an offset with a limit.
'''
import ckan.model as model
q = q.order_by(desc(model.Activity.timestamp)).distinct()
q = q.order_by(desc(model.Activity.timestamp))
if offset:
q = q.offset(offset)
if limit:
q = q.limit(limit)
return q

def _activities_union_all(*qlist):
'''
Return union of two or more queries sorted by timestamp,
and remove duplicates
'''
import ckan.model as model
return model.Session.query(model.Activity).select_from(
union_all(*[q.subquery().select() for q in qlist]))
union_all(*[q.subquery().select() for q in qlist])
).distinct(model.Activity.timestamp)

def _activities_at_offset(q, limit, offset):
'''
Expand Down

0 comments on commit c04c273

Please sign in to comment.