diff --git a/app/controllers/tag_corrections_controller.rb b/app/controllers/tag_corrections_controller.rb index e72ac9a10..ba44d9976 100644 --- a/app/controllers/tag_corrections_controller.rb +++ b/app/controllers/tag_corrections_controller.rb @@ -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 diff --git a/app/logical/tag_correction.rb b/app/logical/tag_correction.rb new file mode 100644 index 000000000..cfbc4746d --- /dev/null +++ b/app/logical/tag_correction.rb @@ -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 diff --git a/app/models/tag.rb b/app/models/tag.rb index 9fff40a42..03af10dcc 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -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 diff --git a/app/views/artists/_quick_search.html.erb b/app/views/artists/_quick_search.html.erb index bd86a2dea..149f8aa86 100644 --- a/app/views/artists/_quick_search.html.erb +++ b/app/views/artists/_quick_search.html.erb @@ -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 %> diff --git a/app/views/pools/_quick_search.html.erb b/app/views/pools/_quick_search.html.erb index cc5c22ece..6044cebed 100644 --- a/app/views/pools/_quick_search.html.erb +++ b/app/views/pools/_quick_search.html.erb @@ -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 %> diff --git a/app/views/tag_corrections/new.html.erb b/app/views/tag_corrections/new.html.erb index f1922a7ff..471519947 100644 --- a/app/views/tag_corrections/new.html.erb +++ b/app/views/tag_corrections/new.html.erb @@ -1,8 +1,18 @@

Fix Tag

-

You can fix the post count for this tag. It will update it from <%= @tag.post_count %> to <%= @tag.real_post_count %>.

+<% @correction.each_server do |server| %> +
+

Server: <%= server.hostname %>

+ +
+<% 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 %> diff --git a/app/views/tag_corrections/show.html.erb b/app/views/tag_corrections/show.html.erb new file mode 100644 index 000000000..4c165df8c --- /dev/null +++ b/app/views/tag_corrections/show.html.erb @@ -0,0 +1,24 @@ +

Tag Correction: <%= @correction.tag.name %>

+ +

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.

+ +<% @correction.each_server do |server| %> +
+

Server: <%= server.hostname %>

+ +
+<% end %> + +

You can try to fix this alias. This will clear the cache and re-save all posts associated with <%= @correction.antecedent_name %>.

+ +<%= 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" %> \ No newline at end of file diff --git a/app/views/tags/_quick_search.html.erb b/app/views/tags/_quick_search.html.erb index 8eec7af8d..fb5e46c26 100644 --- a/app/views/tags/_quick_search.html.erb +++ b/app/views/tags/_quick_search.html.erb @@ -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 %>