Fix postgres error in SQL query

This commit is contained in:
Joseph Schorr 2016-06-30 17:31:46 -04:00
parent 1eec6f53b2
commit 117ccda1cf

View file

@ -231,6 +231,8 @@ def get_visible_repositories(username, namespace=None, include_public=False):
""" Returns the repositories visible to the given user (if any).
"""
if not include_public and not username:
# Short circuit by returning a query that will find no repositories. We need to return a query
# here, as it will be modified by other queries later on.
return Repository.select().where(Repository.id == -1)
query = (Repository
@ -394,6 +396,6 @@ def list_popular_public_repos(action_count_threshold, time_span):
.join(RepositoryActionCount)
.where(RepositoryActionCount.date >= cutoff,
Repository.visibility == get_public_repo_visibility())
.group_by(RepositoryActionCount.repository)
.group_by(RepositoryActionCount.repository, Repository.name, Namespace.username)
.having(fn.Sum(RepositoryActionCount.count) >= action_count_threshold)
.tuples())