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 @@ +
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 %>