diff --git a/app/jobs/tag_batch_change_job.rb b/app/jobs/tag_batch_change_job.rb index fc7f1ddca..621e5ac60 100644 --- a/app/jobs/tag_batch_change_job.rb +++ b/app/jobs/tag_batch_change_job.rb @@ -28,9 +28,10 @@ class TagBatchChangeJob < ApplicationJob def migrate_posts(normalized_antecedent, normalized_consequent) ::Post.tag_match(normalized_antecedent.join(" ")).find_each do |post| - post.reload - tags = (post.tag_array - normalized_antecedent + normalized_consequent).join(" ") - post.update(tag_string: tags) + post.with_lock do + tags = (post.tag_array - normalized_antecedent + normalized_consequent).join(" ") + post.update(tag_string: tags) + end end end diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index 7981c968b..617c1f243 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -136,16 +136,6 @@ class TagAlias < TagRelationship end end - def update_posts - Post.without_timeout do - Post.raw_tag_match(antecedent_name).find_each do |post| - escaped_antecedent_name = Regexp.escape(antecedent_name) - fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{consequent_name} ").strip - post.update(tag_string: fixed_tags) - end - end - end - def rename_wiki_and_artist antecedent_wiki = WikiPage.titled(antecedent_name).first if antecedent_wiki.present? diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index 04d2c2ec8..066e2c56f 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -155,15 +155,6 @@ class TagImplication < TagRelationship end end - def update_posts - Post.without_timeout do - Post.raw_tag_match(antecedent_name).where("true /* TagImplication#update_posts */").find_each do |post| - fixed_tags = "#{post.tag_string} #{descendant_names_string}".strip - post.update(tag_string: fixed_tags) - end - end - end - def approve!(approver: CurrentUser.user, update_topic: true) update(approver: approver, status: "queued") ProcessTagImplicationJob.perform_later(self, update_topic: update_topic) diff --git a/app/models/tag_relationship.rb b/app/models/tag_relationship.rb index 5467453cd..8a38995f3 100644 --- a/app/models/tag_relationship.rb +++ b/app/models/tag_relationship.rb @@ -215,6 +215,16 @@ class TagRelationship < ApplicationRecord Post.fast_count(antecedent_name, skip_cache: true) 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 update_notice TagChangeNoticeService.update_cache( [antecedent_name, consequent_name],