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.
This commit is contained in:
Neil Lalonde 2020-02-14 12:13:17 -05:00
parent fadb2b7157
commit c31039d51f
2 changed files with 5 additions and 0 deletions

View File

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

View File

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