Document left_joins_messageable smell
This commit is contained in:
@@ -11,14 +11,13 @@ class Bubble < ApplicationRecord
|
||||
scope :reverse_chronologically, -> { order created_at: :desc, id: :desc }
|
||||
scope :chronologically, -> { order created_at: :asc, id: :asc }
|
||||
|
||||
# FIXME: Compute activity and comment count at write time so it's easier to query for.
|
||||
scope :left_joins_comments, -> do
|
||||
left_joins(:messages).merge(Message.left_joins_messageable(:comments))
|
||||
end
|
||||
|
||||
scope :ordered_by_activity, -> do
|
||||
left_joins_comments.select("bubbles.*, COUNT(comments.id) + bubbles.boost_count AS activity").group(:id).order("activity DESC")
|
||||
end
|
||||
|
||||
scope :ordered_by_comments, -> do
|
||||
left_joins_comments.select("bubbles.*, COUNT(comments.id) AS comment_count").group(:id).order("comment_count DESC")
|
||||
end
|
||||
|
||||
@@ -5,6 +5,7 @@ class Message < ApplicationRecord
|
||||
|
||||
scope :chronologically, -> { order created_at: :asc, id: :desc }
|
||||
|
||||
# FIXME: Will be made redundant when we compute activity and comment count at write time. See commit.
|
||||
scope :left_joins_messageable, ->(messageable_type) do
|
||||
joins "LEFT OUTER JOIN #{messageable_type} ON messages.messageable_id = #{messageable_type}.id"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user