Batch and tag update changes

This commit is contained in:
Kira 2019-12-28 05:24:06 -08:00
parent 51ad6f5b62
commit 1bf4bbb3f9
5 changed files with 25 additions and 32 deletions

View File

@ -28,9 +28,10 @@ class TagBatchJob < 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

@ -102,11 +102,13 @@ class Tag < ApplicationRecord
end
def increment_post_counts(tag_names)
Tag.where(:name => tag_names).update_all("post_count = post_count + 1")
Tag.where(name: tag_names).order(:name).lock("FOR UPDATE").pluck(1)
Tag.where(name: tag_names).update_all("post_count = post_count + 1")
end
def decrement_post_counts(tag_names)
Tag.where(:name => tag_names).update_all("post_count = post_count - 1")
Tag.where(name: tag_names).order(:name).lock("FOR UPDATE").pluck(1)
Tag.where(name: tag_names).update_all("post_count = post_count - 1")
end
def clean_up_negative_post_counts!

View File

@ -172,6 +172,9 @@ class TagAlias < TagRelationship
forum_updater.update(approval_message(approver), "APPROVED") if update_topic
rename_wiki_and_artist
update(status: 'active', post_count: consequent_tag.post_count)
# TODO: Race condition with indexing jobs here.
antecedent_tag.fix_post_count if antecedent_tag
consequent_tag.fix_post_count if consequent_tag
end
rescue Exception => e
Rails.logger.error("[TA] #{e.message}\n#{e.backtrace}")
@ -265,20 +268,6 @@ class TagAlias < TagRelationship
end
end
def update_posts
Post.without_timeout do
Post.sql_raw_tag_match(antecedent_name).find_each do |post|
post.do_not_version_changes = true
post.tag_string += " "
post.save
end
# TODO: Race condition with indexing jobs here.
antecedent_tag.fix_post_count if antecedent_tag
consequent_tag.fix_post_count if consequent_tag
end
end
def rename_wiki_and_artist
antecedent_wiki = WikiPage.titled(antecedent_name).first
if antecedent_wiki.present?

View File

@ -165,19 +165,6 @@ class TagImplication < TagRelationship
end
def update_posts
Post.without_timeout do
Post.sql_raw_tag_match(antecedent_name).find_each do |post|
fixed_tags = "#{post.tag_string} #{descendant_names_string}".strip
CurrentUser.scoped(creator, creator_ip_addr) do
post.update(
:tag_string => fixed_tags
)
end
end
end
end
def approve!(approver: CurrentUser.user, update_topic: true)
update(status: "queued", approver_id: approver.id)
create_undo_information

View File

@ -210,6 +210,20 @@ class TagRelationship < ApplicationRecord
)
end
def update_posts
Post.without_timeout do
Post.sql_raw_tag_match(antecedent_name).find_each do |post|
post.with_lock do
CurrentUser.scoped(creator, creator_ip_addr) do
post.do_not_version_changes = true
post.tag_string += " "
post.save!
end
end
end
end
end
extend SearchMethods
include MessageMethods
end