Skip to content

Commit

Permalink
FEATURE: ninja op_likes sort for topic lists
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Oct 3, 2014
1 parent 0d1b460 commit cc23bb8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/topic_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TopicQuery
# Maps `order` to a columns in `topics`
SORTABLE_MAPPING = {
'likes' => 'like_count',
'op_likes' => 'op_likes',
'views' => 'views',
'posts' => 'posts_count',
'activity' => 'bumped_at',
Expand Down Expand Up @@ -211,6 +212,10 @@ def apply_ordering(result, options)
return result.references(:categories).order(TopicQuerySQL.order_by_category_sql(sort_dir))
end

if sort_column == 'op_likes'
return result.order("(SELECT like_count FROM posts p3 WHERE p3.topic_id = topics.id AND p3.post_number = 1) #{sort_dir}")
end

result.order("topics.#{sort_column} #{sort_dir}")
end

Expand Down

0 comments on commit cc23bb8

Please sign in to comment.