Skip to content

Commit

Permalink
Cleaning up the has_comments SQL query
Browse files Browse the repository at this point in the history
  • Loading branch information
tavinathanson committed Jan 14, 2015
1 parent 31815eb commit e80157a
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions cycledash/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ def runs():
elif request.method == 'GET':
with tables(db, 'vcfs', 'user_comments') as (con, vcfs, user_comments):
joined = vcfs.outerjoin(user_comments, vcfs.c.id == user_comments.c.vcf_id)
# distinct is needed because user_comments.vcf_id is duplicated across
# user_comment rows
num_comments = func.count(user_comments.c.vcf_id).label('num_comments')
q = select(vcfs.c + [num_comments]).select_from(joined).group_by(
user_comments.c.vcf_id, vcfs.c.id).order_by(desc(vcfs.c.id))
vcfs.c.id).order_by(desc(vcfs.c.id))
vcfs = [dict(v) for v in con.execute(q).fetchall()]
if 'text/html' in request.accept_mimetypes:
return render_template('runs.html', runs=vcfs, run_kvs=RUN_ADDL_KVS)
Expand Down

0 comments on commit e80157a

Please sign in to comment.