diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5ac4811442c..4f60aef2dff 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -293,13 +293,15 @@ class ApplicationController < ActionController::Base Middleware::AnonymousCache.anon_cache(request.env, time_length) end - def fetch_user_from_params(opts=nil) + def fetch_user_from_params(opts=nil, eager_load = []) opts ||= {} user = if params[:username] username_lower = params[:username].downcase.chomp('.json') find_opts = { username_lower: username_lower } find_opts[:active] = true unless opts[:include_inactive] || current_user.try(:staff?) - User.find_by(find_opts) + result = User + (result = result.includes(*eager_load)) if !eager_load.empty? + result.find_by(find_opts) elsif params[:external_id] external_id = params[:external_id].chomp('.json') SingleSignOnRecord.find_by(external_id: external_id).try(:user) diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index ef36592ef53..b3bc5d19310 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -109,7 +109,7 @@ class ListController < ApplicationController [:topics_by, :private_messages, :private_messages_sent, :private_messages_unread, :private_messages_archive, :private_messages_group, :private_messages_group_archive].each do |action| define_method("#{action}") do list_opts = build_topic_list_options - target_user = fetch_user_from_params(include_inactive: current_user.try(:staff?)) + target_user = fetch_user_from_params({ include_inactive: current_user.try(:staff?) }, [:user_stat, :user_option]) guardian.ensure_can_see_private_messages!(target_user.id) unless action == :topics_by list = generate_list_for(action.to_s, target_user, list_opts) url_prefix = "topics" unless action == :topics_by diff --git a/app/serializers/topic_list_item_serializer.rb b/app/serializers/topic_list_item_serializer.rb index d3763cef165..a04c1eeae3c 100644 --- a/app/serializers/topic_list_item_serializer.rb +++ b/app/serializers/topic_list_item_serializer.rb @@ -67,6 +67,7 @@ class TopicListItemSerializer < ListableTopicSerializer def include_tags? SiteSetting.tagging_enabled end + def tags object.tags.map(&:name) end diff --git a/app/serializers/topic_list_serializer.rb b/app/serializers/topic_list_serializer.rb index c0321c7058b..5d4364d4115 100644 --- a/app/serializers/topic_list_serializer.rb +++ b/app/serializers/topic_list_serializer.rb @@ -26,6 +26,7 @@ class TopicListSerializer < ApplicationSerializer def include_tags? SiteSetting.tagging_enabled && SiteSetting.show_filter_by_tag end + def tags Tag.top_tags end diff --git a/lib/topic_query.rb b/lib/topic_query.rb index d2add0c9bb1..d611e544396 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -355,10 +355,10 @@ class TopicQuery options = @options options.reverse_merge!(per_page: per_page_setting) - result = Topic + result = Topic.includes(:tags) if type == :group - result = result.includes(:allowed_groups) + result = result.includes(:allowed_users) result = result.where("topics.id IN (SELECT topic_id FROM topic_allowed_groups WHERE group_id IN ( SELECT group_id FROM group_users WHERE user_id = #{user.id.to_i}) AND