Fix #4130: Remove tag alias corrections.
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
class TagAliasCorrectionsController < ApplicationController
|
||||
before_action :builder_only, only: [:create]
|
||||
|
||||
def create
|
||||
@correction = TagAliasCorrection.new(params[:tag_alias_id])
|
||||
|
||||
if params[:commit] == "Fix"
|
||||
@correction.fix!
|
||||
flash[:notice] = "The fix has been queued and will be processed"
|
||||
end
|
||||
|
||||
redirect_to tag_alias_correction_path(:tag_alias_id => params[:tag_alias_id])
|
||||
end
|
||||
|
||||
def show
|
||||
@correction = TagAliasCorrection.new(params[:tag_alias_id])
|
||||
end
|
||||
end
|
||||
@@ -261,7 +261,7 @@ protected
|
||||
when "moderator/dashboards"
|
||||
/^\/moderator/
|
||||
|
||||
when "tag_aliases", "tag_alias_corrections", "tag_alias_requests"
|
||||
when "tag_aliases", "tag_alias_requests"
|
||||
/^\/tag_aliases/
|
||||
|
||||
when "tag_implications", "tag_implication_requests"
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
class TagAliasCorrection
|
||||
attr_reader :tag_alias_id, :tag_alias
|
||||
delegate :antecedent_name, :consequent_name, :to => :tag_alias
|
||||
|
||||
def initialize(tag_alias_id)
|
||||
@tag_alias_id = tag_alias_id
|
||||
@tag_alias = TagAlias.find(tag_alias_id)
|
||||
end
|
||||
|
||||
def to_json(options = {})
|
||||
statistics_hash.to_json
|
||||
end
|
||||
|
||||
def statistics_hash
|
||||
@statistics_hash ||= {
|
||||
"antecedent_count" => Tag.find_by_name(tag_alias.antecedent_name).try(:post_count),
|
||||
"consequent_count" => Tag.find_by_name(tag_alias.consequent_name).try(:post_count)
|
||||
}
|
||||
end
|
||||
|
||||
def fix!
|
||||
tag_alias.delay(:queue => "default").update_posts
|
||||
end
|
||||
end
|
||||
@@ -33,9 +33,6 @@
|
||||
<% if tag.editable_by?(CurrentUser.user) %>
|
||||
<%= link_to "edit", edit_tag_path(tag) %>
|
||||
<% end %>
|
||||
<% if CurrentUser.is_builder? %>
|
||||
| <%= link_to "fix", new_tag_correction_path(:tag_id => tag.id) %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<div id="c-tag-alias-corrections">
|
||||
<div id="a-show">
|
||||
<h1>Tag Alias Correction: <%= @correction.antecedent_name %> -> <%= @correction.consequent_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>
|
||||
|
||||
<div style="margin-bottom: 1em;">
|
||||
<ul>
|
||||
<li><strong><%= link_to @correction.antecedent_name, posts_path(:tags => @correction.antecedent_name, :raw => true) %></strong> aliased to <strong><%= @correction.statistics_hash["antecedent_cache"] %></strong> in cache</li>
|
||||
<li><strong><%= @correction.consequent_name %></strong> aliased to <strong><%= @correction.statistics_hash["consequent_cache"] %></strong> in cache</li>
|
||||
<li><strong><%= @correction.antecedent_name %></strong> count is <%= @correction.statistics_hash["antecedent_count"] %></li>
|
||||
<li><strong><%= @correction.consequent_name %></strong> count is <%= @correction.statistics_hash["consequent_count"] %></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<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 %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "tag_aliases/secondary_links" %>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
Tag Alias Correction - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
@@ -1 +0,0 @@
|
||||
<%= raw @correction.to_json %>
|
||||
@@ -37,10 +37,6 @@
|
||||
<% if CurrentUser.is_admin? && tag_alias.is_pending? %>
|
||||
| <%= link_to "Approve", approve_tag_alias_path(tag_alias), :remote => true, :method => :post %>
|
||||
<% end %>
|
||||
|
||||
<% if CurrentUser.is_builder? %>
|
||||
| <%= link_to "Fix", tag_alias_correction_path(:tag_alias_id => tag_alias.id) %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -268,7 +268,6 @@ Rails.application.routes.draw do
|
||||
end
|
||||
end
|
||||
resources :tag_aliases do
|
||||
resource :correction, :controller => "tag_alias_corrections"
|
||||
member do
|
||||
post :approve
|
||||
end
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class TagAliasCorrectionTest < ActiveSupport::TestCase
|
||||
context "A tag alias correction" do
|
||||
setup do
|
||||
@mod = FactoryBot.create(:moderator_user)
|
||||
CurrentUser.user = @mod
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa")
|
||||
@tag_alias = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
@tag_alias.update_posts
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "with a bad post count" do
|
||||
setup do
|
||||
Tag.where(:name => "aaa").update_all("post_count = -3")
|
||||
@correction = TagAliasCorrection.new(@tag_alias.id)
|
||||
end
|
||||
|
||||
should "have the correct statistics hash" do
|
||||
assert_equal(-3, @correction.statistics_hash["antecedent_count"])
|
||||
assert_equal(1, @correction.statistics_hash["consequent_count"])
|
||||
end
|
||||
|
||||
should "render to json" do
|
||||
assert_nothing_raised do
|
||||
@correction.to_json
|
||||
end
|
||||
|
||||
assert_nothing_raised do
|
||||
JSON.parse(@correction.to_json)
|
||||
end
|
||||
end
|
||||
|
||||
context "that is fixed" do
|
||||
setup do
|
||||
@correction.fix!
|
||||
end
|
||||
|
||||
should "now have the correct count" do
|
||||
assert_equal(0, Tag.find_by_name("aaa").post_count)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user