forked from e621ng/e621ng
[AvoidPosting] Add caching, order search, and tweak modactions (#713)
This commit is contained in:
parent
6fd03b0507
commit
0500896fd0
@ -94,7 +94,7 @@ class AvoidPostingsController < ApplicationController
|
||||
end
|
||||
|
||||
def search_params
|
||||
permitted_params = %i[creator_name creator_id any_name_matches artist_id artist_name any_other_name_matches group_name details is_active]
|
||||
permitted_params = %i[creator_name creator_id any_name_matches artist_id artist_name any_other_name_matches group_name details is_active order]
|
||||
permitted_params += %i[staff_notes] if CurrentUser.is_staff?
|
||||
permitted_params += %i[ip_addr] if CurrentUser.is_admin?
|
||||
permit_search_params permitted_params
|
||||
|
@ -67,15 +67,15 @@ class ModActionDecorator < ApplicationDecorator
|
||||
|
||||
### Avoid Posting ###
|
||||
when "avoid_posting_create"
|
||||
"Created avoid posting entry for artist \"#{vals['artist_name']}\":/artists/show_or_new?name=#{vals['artist_name']}"
|
||||
"Created \"avoid posting ##{vals['id']}\":/avoid_postings/#{vals['id']} for [[#{vals['artist_name']}]]"
|
||||
when "avoid_posting_update"
|
||||
"Updated avoid posting entry for artist \"#{vals['artist_name']}\":/artists/show_or_new?name=#{vals['artist_name']}"
|
||||
"Updated \"avoid posting ##{vals['id']}\":/avoid_postings/#{vals['id']} for [[#{vals['artist_name']}]]"
|
||||
when "avoid_posting_destroy"
|
||||
"Destroyed avoid posting entry for artist \"#{vals['artist_name']}\":/artists/show_or_new?name=#{vals['artist_name']}"
|
||||
"Destroyed \"avoid posting ##{vals['id']}\":/avoid_postings/#{vals['id']} for [[#{vals['artist_name']}]]"
|
||||
when "avoid_posting_delete"
|
||||
"Deleted avoid posting entry for artist \"#{vals['artist_name']}\":/artists/show_or_new?name=#{vals['artist_name']}"
|
||||
"Deleted \"avoid posting ##{vals['id']}\":/avoid_postings/#{vals['id']} for [[#{vals['artist_name']}]]"
|
||||
when "avoid_posting_undelete"
|
||||
"Undeleted avoid posting entry for artist \"#{vals['artist_name']}\":/artists/show_or_new?name=#{vals['artist_name']}"
|
||||
"Undeleted \"avoid posting ##{vals['id']}\":/avoid_postings/#{vals['id']} for [[#{vals['artist_name']}]]"
|
||||
|
||||
### User ###
|
||||
|
||||
|
@ -2,20 +2,22 @@
|
||||
|
||||
module AvoidPostingHelper
|
||||
def format_avoid_posting_list
|
||||
avoid_postings = AvoidPosting.active.joins(:artist).order("artists.name ASC").group_by(&:header)
|
||||
text = ""
|
||||
avoid_postings.each do |header, entries|
|
||||
text += "h2. #{header} [##{anchor(header)}]\n"
|
||||
entries.each do |dnp|
|
||||
text += "* #{dnp.all_names}"
|
||||
if dnp.pretty_details.present?
|
||||
text += " - #{dnp.pretty_details}"
|
||||
Cache.fetch("avoid_posting_list", expires_in: 1.day) do
|
||||
avoid_postings = AvoidPosting.active.joins(:artist).order("artists.name ASC").group_by(&:header)
|
||||
text = ""
|
||||
avoid_postings.each do |header, entries|
|
||||
text += "h2. #{header} [##{anchor(header)}]\n"
|
||||
entries.each do |dnp|
|
||||
text += "* #{dnp.all_names}"
|
||||
if dnp.pretty_details.present?
|
||||
text += " - #{dnp.pretty_details}"
|
||||
end
|
||||
text += "\n"
|
||||
end
|
||||
text += "\n"
|
||||
end
|
||||
text += "\n"
|
||||
format_text(text)
|
||||
end
|
||||
format_text(text)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -13,6 +13,7 @@ class AvoidPosting < ApplicationRecord
|
||||
after_destroy :log_destroy
|
||||
validates_associated :artist
|
||||
accepts_nested_attributes_for :artist
|
||||
after_commit :invalidate_cache
|
||||
|
||||
scope :active, -> { where(is_active: true) }
|
||||
scope :deleted, -> { where(is_active: false) }
|
||||
@ -96,7 +97,19 @@ class AvoidPosting < ApplicationRecord
|
||||
q = q.attribute_matches(:staff_notes, params[:staff_notes])
|
||||
q = q.where_user(:creator_id, :creator, params)
|
||||
q = q.where("creator_ip_addr <<= ?", params[:ip_addr]) if params[:ip_addr].present?
|
||||
q.apply_basic_order(params)
|
||||
case params[:order]
|
||||
when "artist_name", "artist_name_asc"
|
||||
q = q.joins(:artist).order("artists.name ASC")
|
||||
when "artist_name_desc"
|
||||
q = q.joins(:artist).order("artists.name DESC")
|
||||
when "created_at"
|
||||
q = q.order("created_at DESC")
|
||||
when "updated_at"
|
||||
q = q.order("updated_at DESC")
|
||||
else
|
||||
q = q.apply_basic_order(params)
|
||||
end
|
||||
q
|
||||
end
|
||||
end
|
||||
|
||||
@ -122,6 +135,10 @@ class AvoidPosting < ApplicationRecord
|
||||
""
|
||||
end
|
||||
|
||||
def invalidate_cache
|
||||
Cache.delete("avoid_posting_list")
|
||||
end
|
||||
|
||||
include LogMethods
|
||||
include ApiMethods
|
||||
include ArtistMethods
|
||||
|
@ -13,4 +13,5 @@
|
||||
<%= f.input :staff_notes %>
|
||||
<% end %>
|
||||
<%= f.input :is_active, label: "Active?", collection: [%w[Yes true], %w[No false], %w[Any any]] %>
|
||||
<%= f.input :order, collection: [["Artist Name", "artist_name"], %w[Created created_at], %w[Updated updated_at]], include_blank: true %>
|
||||
<% end %>
|
||||
|
Loading…
Reference in New Issue
Block a user