Skip to content

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

FIX: tag topic counts wrong after adding synonyms

Neil Lalondec31039d51f38
diff --git a/lib/discourse_tagging.rb b/lib/discourse_tagging.rb
index 94b9f2cf93b..af34e95a0ed 100644
--- a/lib/discourse_tagging.rb
+++ b/lib/discourse_tagging.rb
@@ -424,6 +424,9 @@ module DiscourseTagging
end
successful = existing.select { |t| !t.errors.present? }
TopicTag.where(tag_id: successful.map(&:id)).update_all(tag_id: target_tag.id)
+ Scheduler::Defer.later "Update tag topic counts" do
+ Tag.ensure_consistency!
+ end
(existing - successful).presence || true
end
diff --git a/spec/components/discourse_tagging_spec.rb b/spec/components/discourse_tagging_spec.rb
index ee12b4ce37b..35ff67a9a9a 100644
--- a/spec/components/discourse_tagging_spec.rb
+++ b/spec/components/discourse_tagging_spec.rb
@@ -568,6 +568,8 @@ describe DiscourseTagging do
topic = Fabricate(:topic, tags: [tag2])
expect(DiscourseTagging.add_or_create_synonyms_by_name(tag1, [tag2.name])).to eq(true)
expect_same_tag_names(topic.reload.tags, [tag1])
+ expect(tag1.reload.topic_count).to eq(1)
+ expect(tag2.reload.topic_count).to eq(0)
end
end
end