From c6a814ce3f4d99d76a1c026e722d920dbd6732d7 Mon Sep 17 00:00:00 2001 From: albert Date: Sun, 17 Mar 2013 23:03:02 -0400 Subject: [PATCH] add tag correction support --- app/controllers/tag_corrections_controller.rb | 16 ++++++++++++++++ app/models/post.rb | 9 +++++++++ app/models/tag.rb | 6 +++++- app/views/tag_corrections/new.html.erb | 8 ++++++++ app/views/tags/_secondary_links.html.erb | 1 + app/views/tags/edit.html.erb | 2 +- app/views/tags/index.html.erb | 5 ++++- config/routes.rb | 4 ++-- 8 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 app/controllers/tag_corrections_controller.rb create mode 100644 app/views/tag_corrections/new.html.erb diff --git a/app/controllers/tag_corrections_controller.rb b/app/controllers/tag_corrections_controller.rb new file mode 100644 index 000000000..e72ac9a10 --- /dev/null +++ b/app/controllers/tag_corrections_controller.rb @@ -0,0 +1,16 @@ +class TagCorrectionsController < ApplicationController + before_filter :member_only + + def new + @tag = Tag.find(params[:tag_id]) + end + + def create + if params[:commit] == "Fix" + @tag = Tag.find(params[:tag_id]) + @tag.delay.fix_post_count + end + + redirect_to tags_path(:search => {:name_matches => @tag.name}) + end +end diff --git a/app/models/post.rb b/app/models/post.rb index c62540ba5..5c94c3c70 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -587,6 +587,15 @@ class Post < ActiveRecord::Base end module CountMethods + def fix_post_counts + post.set_tag_counts + post.update_column(:tag_count, post.tag_count) + post.update_column(:tag_count_general, post.tag_count_general) + post.update_column(:tag_count_artist, post.tag_count_artist) + post.update_column(:tag_count_copyright, post.tag_count_copyright) + post.update_column(:tag_count_character, post.tag_count_character) + end + def get_count_from_cache(tags) count = Cache.get(count_cache_key(tags)) diff --git a/app/models/tag.rb b/app/models/tag.rb index 7fca72ddd..9fff40a42 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -41,8 +41,12 @@ class Tag < ActiveRecord::Base end end + def real_post_count + Post.raw_tag_match(name).count + end + def fix_post_count - update_column(:post_count, Post.raw_tag_match(name).count) + update_column(:post_count, real_post_count) end end diff --git a/app/views/tag_corrections/new.html.erb b/app/views/tag_corrections/new.html.erb new file mode 100644 index 000000000..f1922a7ff --- /dev/null +++ b/app/views/tag_corrections/new.html.erb @@ -0,0 +1,8 @@ +

Fix Tag

+ +

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

+ +<%= form_tag(tag_correction_path(:tag_id => @tag.id)) do %> + <%= submit_tag "Fix" %> + <%= submit_tag "Cancel" %> +<% end %> diff --git a/app/views/tags/_secondary_links.html.erb b/app/views/tags/_secondary_links.html.erb index 928077846..65e8a2977 100644 --- a/app/views/tags/_secondary_links.html.erb +++ b/app/views/tags/_secondary_links.html.erb @@ -7,6 +7,7 @@ <% if @tag %>
  • |
  • <%= link_to "Edit", edit_tag_path(@tag) %>
  • +
  • <%= link_to "Fix", new_tag_correction_path(:tag_id => @tag.id) %>
  • <% end %> <% end %> diff --git a/app/views/tags/edit.html.erb b/app/views/tags/edit.html.erb index dcbac1f63..29ea1e000 100644 --- a/app/views/tags/edit.html.erb +++ b/app/views/tags/edit.html.erb @@ -4,7 +4,7 @@ <%= simple_form_for(@tag) do |f| %> <%= f.input :category, :collection => Danbooru.config.canonical_tag_category_mapping.to_a, :include_blank => false %> - <%= f.button :submit %> + <%= f.button :submit, "Submit" %> <% end %> diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index c305a1fe4..fa1ad8416 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -16,7 +16,10 @@ <%= link_to("?", wiki_pages_path(:title => tag.name)) %> <%= link_to(tag.name, posts_path(:tags => tag.name)) %> - <%= link_to "edit", edit_tag_path(tag) %> + + <%= link_to "edit", edit_tag_path(tag) %> + | <%= link_to "fix", new_tag_correction_path(:tag_id => tag.id) %> + <% end %> diff --git a/config/routes.rb b/config/routes.rb index 8cc610216..a07dac700 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -156,12 +156,13 @@ Danbooru::Application.routes.draw do end resource :source, :only => [:show] resources :tags do + resource :correction, :only => [:new, :create], :controller => "TagCorrections" collection do get :search end end resources :tag_aliases do - resource :correction, :only => [:new, :create, :show], :controller => "TagAliasCorrections" + resource :correction, :only => [:create, :new, :show], :controller => "TagAliasCorrections" member do post :approve end @@ -169,7 +170,6 @@ Danbooru::Application.routes.draw do get :general_search end end - resource :tag_alias_correction, :only => [:new, :create, :show] resource :tag_alias_request, :only => [:new, :create] resources :tag_implications do member do