BURs: lock posts when updating tags during bulk updates.

Fixes updates sometimes getting clobbered when multiple aliases or mass
updates tried to update the same post at the same time.
This commit is contained in:
evazion
2019-12-27 12:08:17 -06:00
parent 3b4f9ad086
commit 06e12973e2
4 changed files with 14 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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