Skip to content

A platform for community discussion. Free, open, simple.

FIX: CategoryTagStat queries need to exclude PMs with tags

Neil Lalonde991dfadad7f4
diff --git a/app/jobs/onceoff/init_category_tag_stats.rb b/app/jobs/onceoff/init_category_tag_stats.rb
index 43cabe3c725..43abdc0b429 100644
--- a/app/jobs/onceoff/init_category_tag_stats.rb
+++ b/app/jobs/onceoff/init_category_tag_stats.rb
@@ -10,6 +10,7 @@ module Jobs
INNER JOIN topic_tags ON tags.id = topic_tags.tag_id
INNER JOIN topics ON topics.id = topic_tags.topic_id
AND topics.deleted_at IS NULL
+ AND topics.category_id IS NOT NULL
GROUP BY tags.id, topics.category_id
SQL
end
diff --git a/app/models/category_tag_stat.rb b/app/models/category_tag_stat.rb
index e9c8275d618..f201de08cd2 100644
--- a/app/models/category_tag_stat.rb
+++ b/app/models/category_tag_stat.rb
@@ -50,7 +50,9 @@ class CategoryTagStat < ActiveRecord::Base
topics.category_id as category_id
FROM tags
INNER JOIN topic_tags ON tags.id = topic_tags.tag_id
- INNER JOIN topics ON topics.id = topic_tags.topic_id AND topics.deleted_at IS NULL
+ INNER JOIN topics ON topics.id = topic_tags.topic_id
+ AND topics.deleted_at IS NULL
+ AND topics.category_id IS NOT NULL
GROUP BY tags.id, topics.category_id
) x
WHERE stats.tag_id = x.tag_id