Partially revert "PERF: Improve query performance all inbox private messages. (#14304)" (#14344)

This partially reverts commit ddb458343dc39a7a8c99467dcd809b444514fe2c.

Seeing performance degrade on larger sites so back to drawing board on
this one. Instead of the DISTINCT LEFT JOIN, we switch back to
IN(subquery).
This commit is contained in:
Alan Guo Xiang Tan
2021-09-15 11:32:10 +08:00
committed by GitHub
parent ddb458343d
commit 27bad28c53
2 changed files with 40 additions and 30 deletions

View File

@ -973,7 +973,7 @@ class TopicsController < ApplicationController
topic_ids = TopicsBulkAction.new(
current_user,
topic_scope.distinct(false).pluck(:id),
topic_scope.pluck(:id),
type: "dismiss_topics"
).perform!
@ -1245,11 +1245,7 @@ class TopicsController < ApplicationController
if inbox = params[:private_message_inbox]
filter = private_message_filter(topic_query, inbox)
topic_query.options[:limit] = false
topic_query
.filter_private_messages_unread(current_user, filter)
.distinct(false)
.pluck(:id)
topics = topic_query.filter_private_messages_unread(current_user, filter)
else
topics = TopicQuery.unread_filter(topic_query.joined_topic_user, staff: guardian.is_staff?).listable_topics
topics = TopicQuery.tracked_filter(topics, current_user.id) if params[:tracked].to_s == "true"
@ -1268,9 +1264,9 @@ class TopicsController < ApplicationController
if params[:tag_name].present?
topics = topics.joins(:tags).where("tags.name": params[:tag_name])
end
topics.pluck(:id)
end
topics.pluck(:id)
end
def private_message_filter(topic_query, inbox)