tag corrections: remove distributed cache logic (#3943).

Remove logic for displaying the state of the tag category cache on both
servers.
This commit is contained in:
evazion
2018-10-04 13:46:10 -05:00
parent 4ab97a01bd
commit c78dece411
4 changed files with 22 additions and 49 deletions

View File

@@ -1,12 +1,15 @@
class TagCorrectionsController < ApplicationController class TagCorrectionsController < ApplicationController
respond_to :html, :json, :xml
before_action :builder_only, only: [:new, :create] before_action :builder_only, only: [:new, :create]
def new def new
@correction = TagCorrection.new(params[:tag_id]) @correction = TagCorrection.new(params[:tag_id])
respond_with(@correction)
end end
def show def show
@correction = TagCorrection.new(params[:tag_id]) @correction = TagCorrection.new(params[:tag_id])
respond_with(@correction)
end end
def create def create

View File

@@ -1,42 +1,21 @@
class TagCorrection class TagCorrection
attr_reader :tag_id, :tag, :hostname include ActiveModel::Model
include ActiveModel::Serializers::JSON
include ActiveModel::Serializers::Xml
def initialize(tag_id, hostname = Socket.gethostname) attr_reader :tag
@tag_id = tag_id delegate :category, :post_count, :real_post_count, to: :tag
def initialize(tag_id)
@tag = Tag.find(tag_id) @tag = Tag.find(tag_id)
@hostname = hostname
end end
def to_json(options = {}) def attributes
statistics_hash.to_json { post_count: post_count, real_post_count: real_post_count, category: category, category_cache: category_cache, tag: tag }
end end
def statistics_hash def category_cache
@statistics_hash ||= { Cache.get("tc:" + Cache.hash(tag.name))
"category_cache" => Cache.get("tc:" + Cache.hash(tag.name)),
"post_fast_count_cache" => Cache.get("pfc:" + Cache.hash(tag.name))
}
end
def fill_hash!
res = HTTParty.get("https://#{hostname}.#{Danbooru.config.domain}/tags/#{tag_id}/correction.json", Danbooru.config.httparty_options)
if res.success?
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
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 end
def fix! def fix!

View File

@@ -2,18 +2,14 @@
<div id="a-new"> <div id="a-new">
<h1>Fix Tag: <%= @correction.tag.name %></h1> <h1>Fix Tag: <%= @correction.tag.name %></h1>
<% @correction.each_server do |server| %> <div style="margin-bottom: 1em;">
<div style="margin-bottom: 1em;"> <ul>
<h2>Server: <%= server.hostname %></h2> <li><strong>category actual</strong>: <%= @correction.category %></li>
<ul> <li><strong>category memcache</strong>: <%= @correction.category_cache || "none" %></li>
<li><strong>category actual</strong>: <%= @correction.tag.category %></li> <li><strong>post count db cache</strong>: <%= @correction.post_count %></li>
<li><strong>category memcache</strong>: <%= server.statistics_hash["category_cache"] %></li> <li><strong>post count actual:</strong> <%= @correction.real_post_count %></li>
<li><strong>post count memcache</strong>: <%= server.statistics_hash["post_fast_count_cache"] %></li> </ul>
<li><strong>post count db cache</strong>: <%= @correction.tag.post_count %></li> </div>
<li><strong>post count actual:</strong> <%= @correction.tag.real_post_count %></li>
</ul>
</div>
<% end %>
<%= form_tag(tag_correction_path(:tag_id => @correction.tag.id)) do %> <%= form_tag(tag_correction_path(:tag_id => @correction.tag.id)) do %>
<%= submit_tag "Fix" %> <%= submit_tag "Fix" %>

View File

@@ -1,5 +0,0 @@
<%= raw @correction.to_json %>
<% content_for(:page_title) do %>
Tag Correction - <%= Danbooru.config.app_name %>
<% end %>