mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 19:00:32 -06:00
FIX: automatically in/decrement topic_tags.pm_topic_count
This commit is contained in:
parent
be891e1c2e
commit
a512b181d9
@ -3,26 +3,34 @@ class TopicTag < ActiveRecord::Base
|
|||||||
belongs_to :tag
|
belongs_to :tag
|
||||||
|
|
||||||
after_create do
|
after_create do
|
||||||
if topic && topic.archetype != Archetype.private_message
|
if topic
|
||||||
tag.increment!(:topic_count)
|
if topic.archetype == Archetype.private_message
|
||||||
|
tag.increment!(:pm_topic_count)
|
||||||
|
else
|
||||||
|
tag.increment!(:topic_count)
|
||||||
|
|
||||||
if topic.category_id
|
if topic.category_id
|
||||||
if stat = CategoryTagStat.where(tag_id: tag_id, category_id: topic.category_id).first
|
if stat = CategoryTagStat.find_by(tag_id: tag_id, category_id: topic.category_id)
|
||||||
stat.increment!(:topic_count)
|
stat.increment!(:topic_count)
|
||||||
else
|
else
|
||||||
CategoryTagStat.create(tag_id: tag_id, category_id: topic.category_id, topic_count: 1)
|
CategoryTagStat.create(tag_id: tag_id, category_id: topic.category_id, topic_count: 1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
after_destroy do
|
after_destroy do
|
||||||
if topic && topic.archetype != Archetype.private_message
|
if topic
|
||||||
if topic.category_id && stat = CategoryTagStat.where(tag_id: tag_id, category: topic.category_id).first
|
if topic.archetype == Archetype.private_message
|
||||||
stat.topic_count == 1 ? stat.destroy : stat.decrement!(:topic_count)
|
tag.decrement!(:pm_topic_count)
|
||||||
end
|
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)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -181,9 +181,7 @@ module DiscourseTagging
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.hidden_tag_names(guardian = nil)
|
def self.hidden_tag_names(guardian = nil)
|
||||||
return [] if guardian&.is_staff?
|
guardian&.is_staff? ? [] : hidden_tags_query.pluck(:name)
|
||||||
|
|
||||||
hidden_tags_query.pluck(:name)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.hidden_tags_query
|
def self.hidden_tags_query
|
||||||
|
Loading…
Reference in New Issue
Block a user