add post count estimates for bulk update requests

This commit is contained in:
Albert Yi
2019-01-09 15:54:55 -08:00
parent 844b1a81ba
commit f33b23d035
11 changed files with 112 additions and 17 deletions

View File

@@ -78,6 +78,28 @@ class AliasAndImplicationImporter
end
end
def estimate_update_count
tokens = self.class.tokenize(text)
tokens.inject(0) do |sum, token|
case token[0]
when :create_alias
sum + TagAlias.new(antecedent_name: token[1], consequent_name: token[2]).estimate_update_count
when :create_implication
sum + TagImplication.new(antecedent_name: token[1], consequent_name: token[2]).estimate_update_count
when :mass_update
sum + Moderator::TagBatchChange.new(token[1], token[2]).estimate_update_count
when :change_category
sum + Tag.find_by_name(token[1]).try(:post_count) || 0
else
sum + 0
end
end
end
private
def parse(tokens, approver)

View File

@@ -20,6 +20,10 @@ module Moderator
ModAction.log("processed mass update: #{antecedent} -> #{consequent}",:mass_update)
end
def estimate_update_count
PostReadOnly.tag_match(antecedent).count
end
def migrate_posts(normalized_antecedent, normalized_consequent)
::Post.tag_match(normalized_antecedent.join(" ")).find_each do |post|
post.reload