diff --git a/app/models/topic.rb b/app/models/topic.rb index 556130d797a..1b433d84a2a 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -139,14 +139,12 @@ class Topic < ActiveRecord::Base # Query conditions condition = if ids.present? - ["NOT c.read_restricted or c.id in (:cats)", cats: ids] + ["NOT read_restricted OR id IN (:cats)", cats: ids] else - ["NOT c.read_restricted"] + ["NOT read_restricted"] end - where("category_id IS NULL OR category_id IN ( - SELECT c.id FROM categories c - WHERE #{condition[0]})", condition[1]) + where("topics.category_id IS NULL OR topics.category_id IN (SELECT id FROM categories WHERE #{condition[0]})", condition[1]) } attr_accessor :ignore_category_auto_close diff --git a/app/models/user_summary.rb b/app/models/user_summary.rb index a95094e0e5d..fc1c455787e 100644 --- a/app/models/user_summary.rb +++ b/app/models/user_summary.rb @@ -30,7 +30,6 @@ class UserSummary .merge(Topic.listable_topics.visible.secured(@guardian)) .where(user: @user) .where('post_number > 1') - .where('topics.archetype <> ?', Archetype.private_message) .order('posts.like_count DESC, posts.created_at ASC') .limit(MAX_SUMMARY_RESULTS) end @@ -39,7 +38,8 @@ class UserSummary TopicLink .joins(:topic, :post) .includes(:topic, :post) - .where('topics.archetype <> ?', Archetype.private_message) + .where('posts.post_type IN (?)', Topic.visible_post_types(@guardian && @guardian.user)) + .merge(Topic.listable_topics.visible.secured(@guardian)) .where(user: @user) .where(internal: false, reflection: false, quote: false) .order('clicks DESC, topic_links.created_at ASC')