add post count estimates for bulk update requests
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user