implications: don't update posts that already have the new tag.

When approving an implication, only retag posts that are missing the new
tag. Don't try to update posts that already have the tag. This makes
large implication requests faster to process when most of the posts
already have the implied tag.
This commit is contained in:
evazion
2020-12-01 16:10:30 -06:00
parent 4741a52cc4
commit 293b2c0be8
3 changed files with 13 additions and 15 deletions

View File

@@ -110,8 +110,15 @@ class TagImplication < TagRelationship
module ApprovalMethods module ApprovalMethods
def process! def process!
update_posts!
end
def update_posts!
CurrentUser.scoped(User.system) do 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
end end

View File

@@ -118,16 +118,6 @@ class TagRelationship < ApplicationRecord
end end
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) 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) ProcessTagRelationshipJob.perform_later(class_name: self.name, approver: approver, antecedent_name: antecedent_name, consequent_name: consequent_name, forum_topic: forum_topic)
end end

View File

@@ -116,13 +116,14 @@ class TagImplicationTest < ActiveSupport::TestCase
end end
should "update any affected post upon save" do 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: "sword", consequent_name: "weapon", approver: @admin)
TagImplication.approve!(antecedent_name: "aaa", consequent_name: "yyy", approver: @admin)
perform_enqueued_jobs 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 end
context "when calculating implied tags" do context "when calculating implied tags" do