* Refactored tag fix code
* Revert quick search open in new window behavior
This commit is contained in:
@@ -2,15 +2,15 @@ class TagCorrectionsController < ApplicationController
|
||||
before_filter :member_only
|
||||
|
||||
def new
|
||||
@tag = Tag.find(params[:tag_id])
|
||||
@correction = TagCorrection.new(params[:tag_id])
|
||||
end
|
||||
|
||||
def create
|
||||
if params[:commit] == "Fix"
|
||||
@tag = Tag.find(params[:tag_id])
|
||||
@tag.delay.fix_post_count
|
||||
@correction = TagCorrection.new(params[:tag_id])
|
||||
@correction.fix!
|
||||
end
|
||||
|
||||
redirect_to tags_path(:search => {:name_matches => @tag.name})
|
||||
redirect_to tags_path(:search => {:name_matches => @correction.tag.name}), :notice => "Tag will be fixed in a few seconds"
|
||||
end
|
||||
end
|
||||
|
||||
49
app/logical/tag_correction.rb
Normal file
49
app/logical/tag_correction.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
class TagCorrection
|
||||
attr_reader :tag_id, :tag, :hostname
|
||||
|
||||
def initialize(tag_id, hostname = Socket.gethostname)
|
||||
@tag_id = tag_id
|
||||
@tag = Tag.find(tag_id)
|
||||
@hostname = hostname
|
||||
end
|
||||
|
||||
def to_json(options = {})
|
||||
statistics_hash.to_json
|
||||
end
|
||||
|
||||
def statistics_hash
|
||||
@statistics_hash ||= {
|
||||
"category_cache" => Cache.get("tc:" + Cache.sanitize(tag.name)),
|
||||
"post_fast_count_cache" => Cache.get("pfc:" + Cache.sanitize(tag.name))
|
||||
}
|
||||
end
|
||||
|
||||
def fill_hash!
|
||||
Net::HTTP.start(hostname, 80) do |http|
|
||||
http.request_get("/tags/#{tag_id}/correction.json") do |res|
|
||||
if res === Net::HTTPSuccess
|
||||
json = JSON.parse(res.body)
|
||||
statistics_hash["category_cache"] = json["category_cache"]
|
||||
statistics_hash["post_fast_count_cache"] = json["post_fast_count_cache"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def each_server
|
||||
Danbooru.config.all_server_hosts.each do |host|
|
||||
other = TagCorrection.new(tag_id, host)
|
||||
|
||||
if host != Socket.gethostname
|
||||
other.fill_hash!
|
||||
end
|
||||
|
||||
yield other
|
||||
end
|
||||
end
|
||||
|
||||
def fix!
|
||||
tag.delay(:queue => "default").fix_post_count
|
||||
Post.expire_cache_for_all(tag.name)
|
||||
end
|
||||
end
|
||||
@@ -42,7 +42,7 @@ class Tag < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def real_post_count
|
||||
Post.raw_tag_match(name).count
|
||||
@real_post_count ||= Post.raw_tag_match(name).count
|
||||
end
|
||||
|
||||
def fix_post_count
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<%= form_tag(artists_path, :method => :get, :target => "_blank") do %>
|
||||
<%= form_tag(artists_path, :method => :get) do %>
|
||||
<%= text_field "search", "name" %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<%= form_tag(pools_path, :method => :get, :target => "_blank") do %>
|
||||
<%= form_tag(pools_path, :method => :get) do %>
|
||||
<%= text_field "search", "name_matches" %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
<h1>Fix Tag</h1>
|
||||
|
||||
<p>You can fix the post count for this tag. It will update it from <%= @tag.post_count %> to <%= @tag.real_post_count %>.</p>
|
||||
<% @correction.each_server do |server| %>
|
||||
<div style="margin-bottom: 1em;">
|
||||
<h2>Server: <%= server.hostname %></h2>
|
||||
<ul>
|
||||
<li><strong>category cache</strong>: <%= server.statistics_hash["category_cache"] %></li>
|
||||
<li><strong>post fast count cache</strong>: <%= server.statistics_hash["post_fast_count_cache"] %></li>
|
||||
<li><strong>post count</strong>: <%= @correction.tag.post_count %></li>
|
||||
<li><strong>real post count:</strong> <%= @correction.tag.real_post_count %></li>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= form_tag(tag_correction_path(:tag_id => @tag.id)) do %>
|
||||
<%= form_tag(tag_correction_path(:tag_id => @correction.tag.id)) do %>
|
||||
<%= submit_tag "Fix" %>
|
||||
<%= submit_tag "Cancel" %>
|
||||
<% end %>
|
||||
|
||||
24
app/views/tag_corrections/show.html.erb
Normal file
24
app/views/tag_corrections/show.html.erb
Normal file
@@ -0,0 +1,24 @@
|
||||
<h1>Tag Correction: <%= @correction.tag.name %></h1>
|
||||
|
||||
<p>Because tag aliases are cached in memory, they may go out of sync. This action will clear out the cache and fix any lingering posts.</p>
|
||||
|
||||
<% @correction.each_server do |server| %>
|
||||
<div style="margin-bottom: 1em;">
|
||||
<h2>Server: <%= server.hostname %></h2>
|
||||
<ul>
|
||||
<li><strong><%= server.antecedent_name %></strong> aliased to <strong><%= server.statistics_hash["antecedent_cache"] %></strong> in cache</li>
|
||||
<li><strong><%= server.consequent_name %></strong> aliased to <strong><%= server.statistics_hash["consequent_cache"] %></strong> in cache</li>
|
||||
<li><strong><%= server.antecedent_name %></strong> count is <%= server.statistics_hash["antecedent_count"] %></li>
|
||||
<li><strong><%= server.consequent_name %></strong> count is <%= server.statistics_hash["consequent_count"] %></li>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<p>You can try to fix this alias. This will clear the cache and re-save all posts associated with <strong><%= @correction.antecedent_name %></strong>.</p>
|
||||
|
||||
<%= form_tag(tag_alias_correction_path(:tag_alias_id => @correction.tag_alias_id)) do %>
|
||||
<%= submit_tag "Fix" %>
|
||||
<%= submit_tag "Cancel" %>
|
||||
<% end %>
|
||||
|
||||
<%= render "tag_aliases/secondary_links" %>
|
||||
@@ -1,3 +1,3 @@
|
||||
<%= form_tag(tags_path, :method => :get, :target => "_blank") do %>
|
||||
<%= form_tag(tags_path, :method => :get) do %>
|
||||
<%= text_field "search", "name_matches" %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user