From c78dece41139505bf327200b1b3a8be6d7c014cd Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 4 Oct 2018 13:46:10 -0500 Subject: [PATCH] tag corrections: remove distributed cache logic (#3943). Remove logic for displaying the state of the tag category cache on both servers. --- app/controllers/tag_corrections_controller.rb | 3 ++ app/logical/tag_correction.rb | 43 +++++-------------- app/views/tag_corrections/new.html.erb | 20 ++++----- app/views/tag_corrections/show.json.erb | 5 --- 4 files changed, 22 insertions(+), 49 deletions(-) delete mode 100644 app/views/tag_corrections/show.json.erb diff --git a/app/controllers/tag_corrections_controller.rb b/app/controllers/tag_corrections_controller.rb index 5a3635f33..21b9c82e6 100644 --- a/app/controllers/tag_corrections_controller.rb +++ b/app/controllers/tag_corrections_controller.rb @@ -1,12 +1,15 @@ class TagCorrectionsController < ApplicationController + respond_to :html, :json, :xml before_action :builder_only, only: [:new, :create] def new @correction = TagCorrection.new(params[:tag_id]) + respond_with(@correction) end def show @correction = TagCorrection.new(params[:tag_id]) + respond_with(@correction) end def create diff --git a/app/logical/tag_correction.rb b/app/logical/tag_correction.rb index f3efd7c2c..2c8b9fdf9 100644 --- a/app/logical/tag_correction.rb +++ b/app/logical/tag_correction.rb @@ -1,42 +1,21 @@ 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) - @tag_id = tag_id + attr_reader :tag + delegate :category, :post_count, :real_post_count, to: :tag + + def initialize(tag_id) @tag = Tag.find(tag_id) - @hostname = hostname end - def to_json(options = {}) - statistics_hash.to_json + def attributes + { post_count: post_count, real_post_count: real_post_count, category: category, category_cache: category_cache, tag: tag } end - def statistics_hash - @statistics_hash ||= { - "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 + def category_cache + Cache.get("tc:" + Cache.hash(tag.name)) end def fix! diff --git a/app/views/tag_corrections/new.html.erb b/app/views/tag_corrections/new.html.erb index 227bd5a4e..329b7713f 100644 --- a/app/views/tag_corrections/new.html.erb +++ b/app/views/tag_corrections/new.html.erb @@ -2,18 +2,14 @@

Fix Tag: <%= @correction.tag.name %>

- <% @correction.each_server do |server| %> -
-

Server: <%= server.hostname %>

-
    -
  • category actual: <%= @correction.tag.category %>
  • -
  • category memcache: <%= server.statistics_hash["category_cache"] %>
  • -
  • post count memcache: <%= server.statistics_hash["post_fast_count_cache"] %>
  • -
  • post count db cache: <%= @correction.tag.post_count %>
  • -
  • post count actual: <%= @correction.tag.real_post_count %>
  • -
-
- <% end %> +
+
    +
  • category actual: <%= @correction.category %>
  • +
  • category memcache: <%= @correction.category_cache || "none" %>
  • +
  • post count db cache: <%= @correction.post_count %>
  • +
  • post count actual: <%= @correction.real_post_count %>
  • +
+
<%= form_tag(tag_correction_path(:tag_id => @correction.tag.id)) do %> <%= submit_tag "Fix" %> diff --git a/app/views/tag_corrections/show.json.erb b/app/views/tag_corrections/show.json.erb deleted file mode 100644 index 9a29c04aa..000000000 --- a/app/views/tag_corrections/show.json.erb +++ /dev/null @@ -1,5 +0,0 @@ -<%= raw @correction.to_json %> - -<% content_for(:page_title) do %> - Tag Correction - <%= Danbooru.config.app_name %> -<% end %>