a7cb75e468
* [Performance] Optimize queries in conversation/message finders * Add message_finder spec * Fix message_finder spec
30 lines
711 B
Ruby
30 lines
711 B
Ruby
class MessageFinder
|
|
def initialize(conversation, params)
|
|
@conversation = conversation
|
|
@params = params
|
|
end
|
|
|
|
def perform
|
|
current_messages
|
|
end
|
|
|
|
private
|
|
|
|
def conversation_messages
|
|
@conversation.messages.includes(:attachment, user: { avatar_attachment: :blob })
|
|
end
|
|
|
|
def messages
|
|
return conversation_messages if @params[:filter_internal_messages].blank?
|
|
|
|
conversation_messages.where.not('private = ? OR message_type = ?', true, 2)
|
|
end
|
|
|
|
def current_messages
|
|
if @params[:before].present?
|
|
messages.reorder('created_at desc').where('id < ?', @params[:before]).limit(20).reverse
|
|
else
|
|
messages.reorder('created_at desc').limit(20).reverse
|
|
end
|
|
end
|
|
end
|