Skip to content

Commit

Permalink
[#1649] Stats extension. Tag counter works properly
Browse files Browse the repository at this point in the history
Currently on 'Top Tags' tab displayed total amount of tags which includes deleted ones, private and deleted packages

After this change, tags with state=deleted, deleted packages, private packages are filtered out
  • Loading branch information
smotornyuk authored and amercader committed Feb 12, 2015
1 parent 2389401 commit d5e27dd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ckanext/stats/stats.py
Expand Up @@ -75,15 +75,19 @@ def top_tags(cls, limit=10, returned_tag_info='object'): # by package
assert returned_tag_info in ('name', 'id', 'object')
tag = table('tag')
package_tag = table('package_tag')
#TODO filter out tags with state=deleted
package = table('package')
if returned_tag_info == 'name':
from_obj = [package_tag.join(tag)]
tag_column = tag.c.name
else:
from_obj = None
tag_column = package_tag.c.tag_id
j = join(package_tag, package,
package_tag.c.package_id == package.c.id)
s = select([tag_column, func.count(package_tag.c.package_id)],
from_obj=from_obj)
from_obj=from_obj).\
select_from(j).\
where(and_(package_tag.c.state=='active', package.c.private == False, package.c.state == 'active' ))
s = s.group_by(tag_column).\
order_by(func.count(package_tag.c.package_id).desc()).\
limit(limit)
Expand Down

0 comments on commit d5e27dd

Please sign in to comment.