Fix search SQL issues

This commit is contained in:
Joseph Schorr 2015-04-08 17:41:08 -04:00
parent 5ae2975134
commit 4f4bb05621
2 changed files with 154 additions and 126 deletions

View file

@ -961,11 +961,11 @@ def _get_public_repo_visibility():
return _public_repo_visibility_cache
def get_matching_repositories(repo_term, username=None, limit=10):
def get_matching_repositories(repo_term, username=None, limit=10, include_public=True):
namespace_term = repo_term
name_term = repo_term
visible = get_visible_repositories(username)
visible = get_visible_repositories(username, include_public=include_public)
search_clauses = (Repository.name ** ('%' + name_term + '%') |
Namespace.username ** ('%' + namespace_term + '%'))
@ -981,14 +981,18 @@ def get_matching_repositories(repo_term, username=None, limit=10):
return visible.where(search_clauses).limit(limit)
def get_repository_pull_counts(repositories):
repo_pull = LogEntryKind.get(name = 'pull_repo')
if not repositories:
return []
last_month = datetime.now() - timedelta(weeks=4)
return (Repository.select(Repository.id, fn.Count(LogEntry.id))
.where(Repository.id << [r.id for r in repositories])
.join(LogEntry, JOIN_LEFT_OUTER)
.where(LogEntry.kind == repo_pull)
.group_by(LogEntry.repository)
.where(LogEntry.kind == repo_pull, LogEntry.datetime >= last_month)
.group_by(Repository.id, LogEntry.id)
.tuples())
def change_password(user, new_password):