A platform for community discussion. Free, open, simple.
FIX: automatically in/decrement topic_tags.pm_topic_count
Régis Hanola512b181d9a7
diff --git a/app/models/topic_tag.rb b/app/models/topic_tag.rbindex 8c0a8df5012..22edeebad0c 100644--- a/app/models/topic_tag.rb+++ b/app/models/topic_tag.rb@@ -3,26 +3,34 @@ class TopicTag < ActiveRecord::Basebelongs_to :tagafter_create do- if topic && topic.archetype != Archetype.private_message- tag.increment!(:topic_count)+ if topic+ if topic.archetype == Archetype.private_message+ tag.increment!(:pm_topic_count)+ else+ tag.increment!(:topic_count)- if topic.category_id- if stat = CategoryTagStat.where(tag_id: tag_id, category_id: topic.category_id).first- stat.increment!(:topic_count)- else- CategoryTagStat.create(tag_id: tag_id, category_id: topic.category_id, topic_count: 1)+ if topic.category_id+ if stat = CategoryTagStat.find_by(tag_id: tag_id, category_id: topic.category_id)+ stat.increment!(:topic_count)+ else+ CategoryTagStat.create(tag_id: tag_id, category_id: topic.category_id, topic_count: 1)+ endendendendendafter_destroy do- if topic && topic.archetype != Archetype.private_message- if topic.category_id && stat = CategoryTagStat.where(tag_id: tag_id, category: topic.category_id).first- stat.topic_count == 1 ? stat.destroy : stat.decrement!(:topic_count)- end+ if topic+ if topic.archetype == Archetype.private_message+ tag.decrement!(:pm_topic_count)+ else+ if topic.category_id && stat = CategoryTagStat.find_by(tag_id: tag_id, category: topic.category_id)+ stat.topic_count == 1 ? stat.destroy : stat.decrement!(:topic_count)+ end- tag.decrement!(:topic_count)+ tag.decrement!(:topic_count)+ endendendenddiff --git a/lib/discourse_tagging.rb b/lib/discourse_tagging.rbindex 98426e2ed7c..030927df29e 100644--- a/lib/discourse_tagging.rb+++ b/lib/discourse_tagging.rb@@ -181,9 +181,7 @@ module DiscourseTaggingenddef self.hidden_tag_names(guardian = nil)- return [] if guardian&.is_staff?-- hidden_tags_query.pluck(:name)+ guardian&.is_staff? ? [] : hidden_tags_query.pluck(:name)enddef self.hidden_tags_query