forked from e621ng/e621ng
[BUR] Optimize BUR index page
This commit is contained in:
parent
adfa01f275
commit
b4e4e762a4
@ -1,7 +1,7 @@
|
||||
module Admin
|
||||
class DashboardsController < ApplicationController
|
||||
before_action :admin_only
|
||||
|
||||
|
||||
def show
|
||||
@dashboard = AdminDashboard.new
|
||||
end
|
||||
|
@ -54,7 +54,7 @@ class BulkUpdateRequestsController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@bulk_update_requests = BulkUpdateRequest.search(search_params).paginate(params[:page], :limit => params[:limit])
|
||||
@bulk_update_requests = BulkUpdateRequest.search(search_params).includes(:forum_post, :user, :approver).paginate(params[:page], :limit => params[:limit])
|
||||
respond_with(@bulk_update_requests)
|
||||
end
|
||||
|
||||
|
@ -39,60 +39,81 @@ module BulkUpdateRequestsHelper
|
||||
end
|
||||
end
|
||||
|
||||
def script_with_line_breaks(script)
|
||||
escaped_script = AliasAndImplicationImporter.tokenize(script).map do |cmd, arg1, arg2|
|
||||
def collect_script_tags(tokenized)
|
||||
names = ::Set.new()
|
||||
tokenized.each do |cmd, arg1, arg2|
|
||||
case cmd
|
||||
when :create_alias, :create_implication, :remove_alias, :remove_implication, :mass_update, :change_category
|
||||
if approved?(cmd, arg1, arg2)
|
||||
btag = '<s class="approved">'
|
||||
etag = '</s>'
|
||||
elsif failed?(cmd, arg1, arg2)
|
||||
btag = '<s class="failed">'
|
||||
etag = "</s>"
|
||||
else
|
||||
btag = nil
|
||||
etag = nil
|
||||
end
|
||||
end
|
||||
|
||||
case cmd
|
||||
when :create_alias
|
||||
arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i
|
||||
arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i
|
||||
|
||||
"#{btag}create alias " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}"
|
||||
|
||||
when :create_implication
|
||||
arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i
|
||||
arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i
|
||||
|
||||
"#{btag}create implication " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}"
|
||||
|
||||
when :remove_alias
|
||||
arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i
|
||||
arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i
|
||||
|
||||
"#{btag}remove alias " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}"
|
||||
|
||||
when :remove_implication
|
||||
arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i
|
||||
arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i
|
||||
|
||||
"#{btag}remove implication " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}"
|
||||
|
||||
when :mass_update
|
||||
"#{btag}mass update " + link_to(arg1, posts_path(:tags => arg1)) + " -> " + link_to(arg2, posts_path(:tags => arg2)) + "#{etag}"
|
||||
|
||||
when :create_alias, :create_implication, :remove_alias, :remove_implication
|
||||
names.add(arg1)
|
||||
names.add(arg2)
|
||||
when :change_category
|
||||
arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i
|
||||
|
||||
"#{btag}category " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> (#{arg2})#{etag}"
|
||||
|
||||
names.add(arg1)
|
||||
end
|
||||
end.join("\n")
|
||||
end
|
||||
Tag.find_by_name_list(names)
|
||||
end
|
||||
|
||||
def script_with_line_breaks(script)
|
||||
output = Cache.get(Cache.hash((CurrentUser.is_moderator? ? "mod" : "") + script), 3600) do
|
||||
script_tokenized = AliasAndImplicationImporter.tokenize(script)
|
||||
script_tags = collect_script_tags(script_tokenized)
|
||||
escaped_script = script_tokenized.map do |cmd, arg1, arg2|
|
||||
case cmd
|
||||
when :create_alias, :create_implication, :remove_alias, :remove_implication, :mass_update, :change_category
|
||||
if approved?(cmd, arg1, arg2)
|
||||
btag = '<s class="approved">'
|
||||
etag = '</s>'
|
||||
elsif failed?(cmd, arg1, arg2)
|
||||
btag = '<s class="failed">'
|
||||
etag = "</s>"
|
||||
else
|
||||
btag = nil
|
||||
etag = nil
|
||||
end
|
||||
end
|
||||
|
||||
case cmd
|
||||
when :create_alias
|
||||
arg1_count = script_tags[arg1].try(:post_count).to_i
|
||||
arg2_count = script_tags[arg2].try(:post_count).to_i
|
||||
|
||||
"#{btag}create alias " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}"
|
||||
|
||||
when :create_implication
|
||||
arg1_count = script_tags[arg1].try(:post_count).to_i
|
||||
arg2_count = script_tags[arg2].try(:post_count).to_i
|
||||
|
||||
"#{btag}create implication " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}"
|
||||
|
||||
when :remove_alias
|
||||
arg1_count = script_tags[arg1].try(:post_count).to_i
|
||||
arg2_count = script_tags[arg2].try(:post_count).to_i
|
||||
|
||||
"#{btag}remove alias " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}"
|
||||
|
||||
when :remove_implication
|
||||
arg1_count = script_tags[arg1].try(:post_count).to_i
|
||||
arg2_count = script_tags[arg2].try(:post_count).to_i
|
||||
|
||||
"#{btag}remove implication " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}"
|
||||
|
||||
when :mass_update
|
||||
"#{btag}mass update " + link_to(arg1, posts_path(:tags => arg1)) + " -> " + link_to(arg2, posts_path(:tags => arg2)) + "#{etag}"
|
||||
|
||||
when :change_category
|
||||
arg1_count = script_tags[arg1].try(:post_count).to_i
|
||||
|
||||
"#{btag}category " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> (#{arg2})#{etag}"
|
||||
|
||||
end
|
||||
end.join("\n")
|
||||
|
||||
escaped_script.gsub(/\n/m, "<br>")
|
||||
rescue AliasAndImplicationImporter::Error
|
||||
"!!!!!!Invalid Script!!!!!!"
|
||||
end
|
||||
|
||||
output.html_safe
|
||||
|
||||
escaped_script.gsub(/\n/m, "<br>").html_safe
|
||||
rescue AliasAndImplicationImporter::Error
|
||||
"!!!!!!Invalid Script!!!!!!"
|
||||
end
|
||||
end
|
||||
|
@ -287,6 +287,15 @@ class Tag < ApplicationRecord
|
||||
find_by_name(normalize_name(name))
|
||||
end
|
||||
|
||||
def find_by_name_list(names)
|
||||
names = names.map {|x| [normalize_name(x), nil]}.to_h
|
||||
existing = Tag.where(name: names.keys).to_a
|
||||
existing.each do |x|
|
||||
names[x.name] = x
|
||||
end
|
||||
names
|
||||
end
|
||||
|
||||
def find_or_create_by_name_list(names, creator: CurrentUser.user)
|
||||
names = names.map {|x| normalize_name(x)}
|
||||
names = names.map do |x|
|
||||
|
Loading…
Reference in New Issue
Block a user