Skip to content
Permalink
Browse files

FIX: tag topic counts wrong after adding synonyms

After adding a tag as a synonym of another tag,
both tags will have the wrong topic counts. It's
corrected within 12 hours by the EnsureDbConsistency
job. This fix ensures the topic counts are updated
much sooner.
  • Loading branch information
nlalonde committed Feb 14, 2020
1 parent fadb2b7 commit c31039d51f386ba7582c8c0cf93a64b806852549
Showing with 5 additions and 0 deletions.
  1. +3 −0 lib/discourse_tagging.rb
  2. +2 −0 spec/components/discourse_tagging_spec.rb
@@ -424,6 +424,9 @@ def self.add_or_create_synonyms_by_name(target_tag, synonym_names)
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

@@ -568,6 +568,8 @@
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

0 comments on commit c31039d

Please sign in to comment.
You can’t perform that action at this time.