FIX: user summary's "most liked by" query

This commit is contained in:
Régis Hanol 2016-04-17 12:21:27 +02:00
parent 2db42e970d
commit ae4dd6e679
1 changed files with 6 additions and 1 deletions

View File

@ -52,7 +52,12 @@ class UserSummary
def most_liked_by_users
likers_ids = []
counts = []
UserAction.where(user: @user)
UserAction.joins("JOIN posts ON posts.id = user_actions.target_post_id")
.joins("JOIN topics ON topics.id = posts.topic_id")
.where("posts.deleted_at IS NULL")
.where("topics.deleted_at IS NULL")
.where("topics.archetype <> '#{Archetype.private_message}'")
.where(user: @user)
.where(action_type: UserAction::WAS_LIKED)
.group(:acting_user_id)
.order("COUNT(*) DESC")