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

View File

@@ -229,4 +229,8 @@ class BulkUpdateRequest < ApplicationRecord
def is_rejected?
status == "rejected"
end
def estimate_update_count
AliasAndImplicationImporter.new(script, nil).estimate_update_count
end
end

View File

@@ -192,6 +192,10 @@ class TagRelationship < ApplicationRecord
end
end
def estimate_update_count
Post.fast_count(antecedent_name, skip_cache: true)
end
extend SearchMethods
include MessageMethods
end

View File

@@ -9,6 +9,7 @@
<li><strong>Creator</strong> <%= link_to_user @bulk_update_request.user %></li>
<li><strong>Date</strong> <%= @bulk_update_request.created_at %></li>
<li><strong>Status</strong>: <%= @bulk_update_request.status %></li>
<li><strong title="How many posts will be affected">Estimate</strong>: <%= @bulk_update_request.estimate_update_count %></li>
<% if CurrentUser.is_admin? && @bulk_update_request.is_pending? %>
<li><strong>Commands</strong> <%= link_to "Approve", approve_bulk_update_request_path(@bulk_update_request), :method => :post %></li>