diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index f8dc34bbe..ab7da6bc8 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -110,8 +110,15 @@ class TagImplication < TagRelationship module ApprovalMethods def process! + update_posts! + end + + def update_posts! CurrentUser.scoped(User.system) do - update_posts + Post.system_tag_match("#{antecedent_name} -#{consequent_name}").find_each do |post| + post.lock! + post.save! + end end end diff --git a/app/models/tag_relationship.rb b/app/models/tag_relationship.rb index 3693f84cb..d6b0f5c73 100644 --- a/app/models/tag_relationship.rb +++ b/app/models/tag_relationship.rb @@ -118,16 +118,6 @@ class TagRelationship < ApplicationRecord end end - def update_posts - Post.without_timeout do - Post.raw_tag_match(antecedent_name).find_each do |post| - post.with_lock do - post.save! - end - end - end - end - def self.approve!(antecedent_name:, consequent_name:, approver:, forum_topic: nil) ProcessTagRelationshipJob.perform_later(class_name: self.name, approver: approver, antecedent_name: antecedent_name, consequent_name: consequent_name, forum_topic: forum_topic) end diff --git a/test/unit/tag_implication_test.rb b/test/unit/tag_implication_test.rb index 99a84de10..f0f8d3625 100644 --- a/test/unit/tag_implication_test.rb +++ b/test/unit/tag_implication_test.rb @@ -116,13 +116,14 @@ class TagImplicationTest < ActiveSupport::TestCase end should "update any affected post upon save" do - p1 = FactoryBot.create(:post, :tag_string => "aaa bbb ccc") + p1 = create(:post, tag_string: "sword") + p2 = create(:post, tag_string: "sword weapon") - TagImplication.approve!(antecedent_name: "aaa", consequent_name: "xxx", approver: @admin) - TagImplication.approve!(antecedent_name: "aaa", consequent_name: "yyy", approver: @admin) + TagImplication.approve!(antecedent_name: "sword", consequent_name: "weapon", approver: @admin) perform_enqueued_jobs - assert_equal("aaa bbb ccc xxx yyy", p1.reload.tag_string) + assert_equal("sword weapon", p1.reload.tag_string) + assert_equal("sword weapon", p2.reload.tag_string) end context "when calculating implied tags" do