FIX: CategoryTagStat queries need to exclude PMs with tags

This commit is contained in:
Neil Lalonde 2018-02-15 12:13:42 -05:00
parent fdd8ce9722
commit 991dfadad7
2 changed files with 4 additions and 1 deletions

View File

@ -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

View File

@ -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