add tag correction support

This commit is contained in:
albert
2013-03-17 23:03:02 -04:00
parent 6cb85fcfdf
commit c6a814ce3f
8 changed files with 46 additions and 5 deletions

View File

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

View File

@@ -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))

View File

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

View File

@@ -0,0 +1,8 @@
<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>
<%= form_tag(tag_correction_path(:tag_id => @tag.id)) do %>
<%= submit_tag "Fix" %>
<%= submit_tag "Cancel" %>
<% end %>

View File

@@ -7,6 +7,7 @@
<% if @tag %>
<li>|</li>
<li><%= link_to "Edit", edit_tag_path(@tag) %></li>
<li><%= link_to "Fix", new_tag_correction_path(:tag_id => @tag.id) %></li>
<% end %>
</menu>
<% end %>

View File

@@ -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 %>
</div>
</div>

View File

@@ -16,7 +16,10 @@
<%= link_to("?", wiki_pages_path(:title => tag.name)) %>
<%= link_to(tag.name, posts_path(:tags => tag.name)) %>
</td>
<td><%= link_to "edit", edit_tag_path(tag) %></td>
<td>
<%= link_to "edit", edit_tag_path(tag) %>
| <%= link_to "fix", new_tag_correction_path(:tag_id => tag.id) %>
</td>
</tr>
<% end %>
</tbody>

View File

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