searchable: refactor searchable_includes.
Pass searchable associations directly to search_attributes instead of defining them separately in searchable_includes.
This commit is contained in:
@@ -155,7 +155,6 @@ module Searchable
|
|||||||
indifferent_params = params.try(:with_indifferent_access) || params.try(:to_unsafe_h)
|
indifferent_params = params.try(:with_indifferent_access) || params.try(:to_unsafe_h)
|
||||||
raise ArgumentError, "unable to process params" if indifferent_params.nil?
|
raise ArgumentError, "unable to process params" if indifferent_params.nil?
|
||||||
|
|
||||||
attributes += searchable_includes
|
|
||||||
attributes.reduce(all) do |relation, attribute|
|
attributes.reduce(all) do |relation, attribute|
|
||||||
relation.search_attribute(attribute, indifferent_params, CurrentUser.user)
|
relation.search_attribute(attribute, indifferent_params, CurrentUser.user)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -93,10 +93,6 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
|
|
||||||
concerning :SearchMethods do
|
concerning :SearchMethods do
|
||||||
class_methods do
|
class_methods do
|
||||||
def searchable_includes
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
|
|
||||||
def model_restriction(table)
|
def model_restriction(table)
|
||||||
table.project(1)
|
table.project(1)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ class Artist < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :is_banned, :name, :group_name, :other_names)
|
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :is_banned, :name, :group_name, :other_names, :urls, :wiki_page, :tag_alias, :tag)
|
||||||
|
|
||||||
if params[:any_other_name_like]
|
if params[:any_other_name_like]
|
||||||
q = q.any_other_name_like(params[:any_other_name_like])
|
q = q.any_other_name_like(params[:any_other_name_like])
|
||||||
@@ -295,10 +295,6 @@ class Artist < ApplicationRecord
|
|||||||
super.where(table[:is_deleted].eq(false))
|
super.where(table[:is_deleted].eq(false))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:urls, :wiki_page, :tag_alias, :tag]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:members, :urls, :wiki_page, :tag_alias, :tag]
|
[:members, :urls, :wiki_page, :tag_alias, :tag]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class ArtistCommentary < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :original_title, :original_description, :translated_title, :translated_description)
|
q = search_attributes(params, :id, :created_at, :updated_at, :original_title, :original_description, :translated_title, :translated_description, :post)
|
||||||
|
|
||||||
if params[:text_matches].present?
|
if params[:text_matches].present?
|
||||||
q = q.text_matches(params[:text_matches])
|
q = q.text_matches(params[:text_matches])
|
||||||
@@ -144,10 +144,6 @@ class ArtistCommentary < ApplicationRecord
|
|||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
include VersionMethods
|
include VersionMethods
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:post]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:post]
|
[:post]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class ArtistCommentaryVersion < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :original_title, :original_description, :translated_title, :translated_description)
|
q = search_attributes(params, :id, :created_at, :updated_at, :original_title, :original_description, :translated_title, :translated_description, :post, :updater)
|
||||||
|
|
||||||
if params[:text_matches].present?
|
if params[:text_matches].present?
|
||||||
q = q.text_matches(params[:text_matches])
|
q = q.text_matches(params[:text_matches])
|
||||||
@@ -55,10 +55,6 @@ class ArtistCommentaryVersion < ApplicationRecord
|
|||||||
self[field].strip.empty? && (previous.nil? || previous[field].strip.empty?)
|
self[field].strip.empty? && (previous.nil? || previous[field].strip.empty?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:post, :updater]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:post, :updater]
|
[:post, :updater]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class ArtistUrl < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params = {})
|
def self.search(params = {})
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :url, :normalized_url, :is_active)
|
q = search_attributes(params, :id, :created_at, :updated_at, :url, :normalized_url, :is_active, :artist)
|
||||||
|
|
||||||
q = q.url_matches(params[:url_matches])
|
q = q.url_matches(params[:url_matches])
|
||||||
q = q.normalized_url_matches(params[:normalized_url_matches])
|
q = q.normalized_url_matches(params[:normalized_url_matches])
|
||||||
@@ -126,10 +126,6 @@ class ArtistUrl < ApplicationRecord
|
|||||||
errors.add(:url, "'#{uri}' is malformed: #{error}")
|
errors.add(:url, "'#{uri}' is malformed: #{error}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:artist]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:artist]
|
[:artist]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class ArtistVersion < ApplicationRecord
|
|||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :is_banned, :name, :group_name, :urls, :other_names)
|
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :is_banned, :name, :group_name, :urls, :other_names, :updater, :artist)
|
||||||
q = q.text_attribute_matches(:name, params[:name_matches])
|
q = q.text_attribute_matches(:name, params[:name_matches])
|
||||||
q = q.text_attribute_matches(:group_name, params[:group_name_matches])
|
q = q.text_attribute_matches(:group_name, params[:group_name_matches])
|
||||||
|
|
||||||
@@ -103,10 +103,6 @@ class ArtistVersion < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:updater, :artist]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:updater, :artist]
|
[:updater, :artist]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class Ban < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :expires_at, :reason)
|
q = search_attributes(params, :id, :created_at, :updated_at, :expires_at, :reason, :user, :banner)
|
||||||
q = q.text_attribute_matches(:reason, params[:reason_matches])
|
q = q.text_attribute_matches(:reason, params[:reason_matches])
|
||||||
|
|
||||||
q = q.expired if params[:expired].to_s.truthy?
|
q = q.expired if params[:expired].to_s.truthy?
|
||||||
@@ -87,10 +87,6 @@ class Ban < ApplicationRecord
|
|||||||
ModAction.log(%{Unbanned <@#{user_name}>}, :user_unban)
|
ModAction.log(%{Unbanned <@#{user_name}>}, :user_unban)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:user, :banner]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:user, :banner]
|
[:user, :banner]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class BulkUpdateRequest < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search(params = {})
|
def search(params = {})
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :script, :tags)
|
q = search_attributes(params, :id, :created_at, :updated_at, :script, :tags, :user, :forum_topic, :forum_post, :approver)
|
||||||
q = q.text_attribute_matches(:script, params[:script_matches])
|
q = q.text_attribute_matches(:script, params[:script_matches])
|
||||||
|
|
||||||
if params[:status].present?
|
if params[:status].present?
|
||||||
@@ -126,10 +126,6 @@ class BulkUpdateRequest < ApplicationRecord
|
|||||||
status == "rejected"
|
status == "rejected"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:user, :forum_topic, :forum_post, :approver]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:user, :forum_topic, :forum_post, :approver]
|
[:user, :forum_topic, :forum_post, :approver]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class Comment < ApplicationRecord
|
|||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :is_sticky, :do_not_bump_post, :body, :score)
|
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :is_sticky, :do_not_bump_post, :body, :score, :post, :creator, :updater)
|
||||||
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index)
|
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index)
|
||||||
|
|
||||||
case params[:order]
|
case params[:order]
|
||||||
@@ -137,10 +137,6 @@ class Comment < ApplicationRecord
|
|||||||
DText.quote(body, creator.name)
|
DText.quote(body, creator.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:post, :creator, :updater]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:post, :creator, :updater]
|
[:post, :creator, :updater]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class CommentVote < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :score)
|
q = search_attributes(params, :id, :created_at, :updated_at, :score, :comment, :user)
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -37,10 +37,6 @@ class CommentVote < ApplicationRecord
|
|||||||
score == -1
|
score == -1
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:comment, :user]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:comment, :user]
|
[:comment, :user]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class Dmail < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_read, :is_deleted, :title, :body)
|
q = search_attributes(params, :id, :created_at, :updated_at, :is_read, :is_deleted, :title, :body, :to, :from)
|
||||||
q = q.text_attribute_matches(:title, params[:title_matches])
|
q = q.text_attribute_matches(:title, params[:title_matches])
|
||||||
q = q.text_attribute_matches(:body, params[:message_matches], index_column: :message_index)
|
q = q.text_attribute_matches(:body, params[:message_matches], index_column: :message_index)
|
||||||
|
|
||||||
@@ -180,10 +180,6 @@ class Dmail < ApplicationRecord
|
|||||||
key ? "dmail ##{id}/#{self.key}" : "dmail ##{id}"
|
key ? "dmail ##{id}/#{self.key}" : "dmail ##{id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:to, :from]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:owner, :to, :from]
|
[:owner, :to, :from]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class DtextLink < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :link_type, :link_target)
|
q = search_attributes(params, :id, :created_at, :updated_at, :link_type, :link_target, :model, :linked_wiki, :linked_tag)
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -48,10 +48,6 @@ class DtextLink < ApplicationRecord
|
|||||||
where(link_type: :wiki_link)
|
where(link_type: :wiki_link)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:model, :linked_wiki, :linked_tag]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:model, :linked_wiki, :linked_tag]
|
[:model, :linked_wiki, :linked_tag]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class FavoriteGroup < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :name, :is_public, :post_ids)
|
q = search_attributes(params, :id, :created_at, :updated_at, :name, :is_public, :post_ids, :creator)
|
||||||
|
|
||||||
if params[:name_matches].present?
|
if params[:name_matches].present?
|
||||||
q = q.name_matches(params[:name_matches])
|
q = q.name_matches(params[:name_matches])
|
||||||
@@ -163,10 +163,6 @@ class FavoriteGroup < ApplicationRecord
|
|||||||
post_ids.include?(post_id)
|
post_ids.include?(post_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:creator]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:creator]
|
[:creator]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class ForumPost < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :body)
|
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :body, :creator, :updater, :topic, :dtext_links, :votes, :tag_alias, :tag_implication, :bulk_update_request)
|
||||||
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :text_index)
|
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :text_index)
|
||||||
|
|
||||||
if params[:linked_to].present?
|
if params[:linked_to].present?
|
||||||
@@ -163,10 +163,6 @@ class ForumPost < ApplicationRecord
|
|||||||
"forum ##{id}"
|
"forum ##{id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:creator, :updater, :topic, :dtext_links, :votes, :tag_alias, :tag_implication, :bulk_update_request]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:creator, :updater, :topic, :dtext_links, :votes, :tag_alias, :tag_implication, :bulk_update_request]
|
[:creator, :updater, :topic, :dtext_links, :votes, :tag_alias, :tag_implication, :bulk_update_request]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class ForumPostVote < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :score)
|
q = search_attributes(params, :id, :created_at, :updated_at, :score, :creator, :forum_post)
|
||||||
q = q.forum_post_matches(params[:forum_post])
|
q = q.forum_post_matches(params[:forum_post])
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
@@ -58,10 +58,6 @@ class ForumPostVote < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:creator, :forum_post]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:creator, :forum_post]
|
[:creator, :forum_post]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ class ForumTopic < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_sticky, :is_locked, :is_deleted, :category_id, :title, :response_count)
|
q = search_attributes(params, :id, :created_at, :updated_at, :is_sticky, :is_locked, :is_deleted, :category_id, :title, :response_count, :creator, :updater, :forum_posts, :bulk_update_requests, :tag_aliases, :tag_implications)
|
||||||
q = q.text_attribute_matches(:title, params[:title_matches], index_column: :text_index)
|
q = q.text_attribute_matches(:title, params[:title_matches], index_column: :text_index)
|
||||||
|
|
||||||
if params[:is_private].to_s.truthy?
|
if params[:is_private].to_s.truthy?
|
||||||
@@ -189,10 +189,6 @@ class ForumTopic < ApplicationRecord
|
|||||||
title.gsub(/\A\[APPROVED\]|\[REJECTED\]/, "")
|
title.gsub(/\A\[APPROVED\]|\[REJECTED\]/, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:creator, :updater, :forum_posts, :bulk_update_requests, :tag_aliases, :tag_implications]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:creator, :updater, :original_post]
|
[:creator, :updater, :original_post]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class IpAddress < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :ip_addr)
|
q = search_attributes(params, :ip_addr, :user, :model)
|
||||||
q.order(created_at: :desc)
|
q.order(created_at: :desc)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -49,10 +49,6 @@ class IpAddress < ApplicationRecord
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:user, :model]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:user, :model]
|
[:user, :model]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class IpBan < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :reason)
|
q = search_attributes(params, :id, :created_at, :updated_at, :reason, :creator)
|
||||||
q = q.text_attribute_matches(:reason, params[:reason_matches])
|
q = q.text_attribute_matches(:reason, params[:reason_matches])
|
||||||
|
|
||||||
if params[:ip_addr].present?
|
if params[:ip_addr].present?
|
||||||
@@ -77,10 +77,6 @@ class IpBan < ApplicationRecord
|
|||||||
super(ip_addr.strip)
|
super(ip_addr.strip)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:creator]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:creator]
|
[:creator]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class ModAction < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :category, :description)
|
q = search_attributes(params, :id, :created_at, :updated_at, :category, :description, :creator)
|
||||||
q = q.text_attribute_matches(:description, params[:description_matches])
|
q = q.text_attribute_matches(:description, params[:description_matches])
|
||||||
|
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
@@ -75,10 +75,6 @@ class ModAction < ApplicationRecord
|
|||||||
create(creator: user, description: desc, category: categories[cat])
|
create(creator: user, description: desc, category: categories[cat])
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:creator]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:creator]
|
[:creator]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -82,16 +82,12 @@ class ModerationReport < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :reason)
|
q = search_attributes(params, :id, :created_at, :updated_at, :reason, :creator, :model)
|
||||||
q = q.text_attribute_matches(:reason, params[:reason_matches])
|
q = q.text_attribute_matches(:reason, params[:reason_matches])
|
||||||
|
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:creator, :model]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:creator, :model]
|
[:creator, :model]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class Note < ApplicationRecord
|
|||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_active, :x, :y, :width, :height, :body, :version)
|
q = search_attributes(params, :id, :created_at, :updated_at, :is_active, :x, :y, :width, :height, :body, :version, :post)
|
||||||
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index)
|
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index)
|
||||||
|
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
@@ -127,10 +127,6 @@ class Note < ApplicationRecord
|
|||||||
new_note.save
|
new_note.save
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:post]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:post]
|
[:post]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ class NoteVersion < ApplicationRecord
|
|||||||
belongs_to_updater :counter_cache => "note_update_count"
|
belongs_to_updater :counter_cache => "note_update_count"
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_active, :x, :y, :width, :height, :body, :version)
|
q = search_attributes(params, :id, :created_at, :updated_at, :is_active, :x, :y, :width, :height, :body, :version, :updater, :note, :post)
|
||||||
q = q.text_attribute_matches(:body, params[:body_matches])
|
q = q.text_attribute_matches(:body, params[:body_matches])
|
||||||
|
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
@@ -69,10 +69,6 @@ class NoteVersion < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:updater, :note, :post]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:updater, :note, :post]
|
[:updater, :note, :post]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,16 +4,12 @@ class PixivUgoiraFrameData < ApplicationRecord
|
|||||||
serialize :data
|
serialize :data
|
||||||
before_validation :normalize_data, on: :create
|
before_validation :normalize_data, on: :create
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:post]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:post]
|
[:post]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :id, :data, :content_type)
|
q = search_attributes(params, :id, :data, :content_type, :post)
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1296,7 +1296,10 @@ class Post < ApplicationRecord
|
|||||||
:image_height, :tag_count, :has_children, :has_active_children,
|
:image_height, :tag_count, :has_children, :has_active_children,
|
||||||
:is_note_locked, :is_rating_locked, :is_status_locked, :is_pending,
|
:is_note_locked, :is_rating_locked, :is_status_locked, :is_pending,
|
||||||
:is_flagged, :is_deleted, :is_banned, :last_comment_bumped_at,
|
:is_flagged, :is_deleted, :is_banned, :last_comment_bumped_at,
|
||||||
:last_commented_at, :last_noted_at, :uploader_ip_addr
|
:last_commented_at, :last_noted_at, :uploader_ip_addr,
|
||||||
|
:uploader, :updater, :approver, :parent, :upload, :artist_commentary,
|
||||||
|
:flags, :appeals, :notes, :comments, :children, :approvals,
|
||||||
|
:replacements, :pixiv_ugoira_frame_data
|
||||||
)
|
)
|
||||||
|
|
||||||
if params[:tags].present?
|
if params[:tags].present?
|
||||||
@@ -1499,10 +1502,6 @@ class Post < ApplicationRecord
|
|||||||
super.where(table[:is_pending].eq(false)).where(table[:is_flagged].eq(false)).where(table[:is_deleted].eq(false))
|
super.where(table[:is_pending].eq(false)).where(table[:is_flagged].eq(false)).where(table[:is_deleted].eq(false))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:uploader, :updater, :approver, :parent, :upload, :artist_commentary, :flags, :appeals, :notes, :comments, :children, :approvals, :replacements, :pixiv_ugoira_frame_data]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:uploader, :updater, :approver, :parent, :upload, :artist_commentary, :flags, :appeals, :notes, :comments, :children, :approvals, :replacements, :pixiv_ugoira_frame_data]
|
[:uploader, :updater, :approver, :parent, :upload, :artist_commentary, :flags, :appeals, :notes, :comments, :children, :approvals, :replacements, :pixiv_ugoira_frame_data]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class PostAppeal < ApplicationRecord
|
|||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :reason, :status)
|
q = search_attributes(params, :id, :created_at, :updated_at, :reason, :status, :creator, :post)
|
||||||
q = q.text_attribute_matches(:reason, params[:reason_matches])
|
q = q.text_attribute_matches(:reason, params[:reason_matches])
|
||||||
|
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
@@ -34,10 +34,6 @@ class PostAppeal < ApplicationRecord
|
|||||||
errors.add(:post, "cannot be appealed") if post.is_status_locked? || !post.is_appealable?
|
errors.add(:post, "cannot be appealed") if post.is_status_locked? || !post.is_appealable?
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:creator, :post]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:creator, :post]
|
[:creator, :post]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -38,14 +38,10 @@ class PostApproval < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :post, :user)
|
q = search_attributes(params, :id, :created_at, :updated_at, :user, :post)
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:user, :post]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:user, :post]
|
[:user, :post]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class PostDisapproval < ApplicationRecord
|
|||||||
concerning :SearchMethods do
|
concerning :SearchMethods do
|
||||||
class_methods do
|
class_methods do
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :message, :reason)
|
q = search_attributes(params, :id, :created_at, :updated_at, :message, :reason, :user, :post)
|
||||||
q = q.text_attribute_matches(:message, params[:message_matches])
|
q = q.text_attribute_matches(:message, params[:message_matches])
|
||||||
|
|
||||||
q = q.with_message if params[:has_message].to_s.truthy?
|
q = q.with_message if params[:has_message].to_s.truthy?
|
||||||
@@ -39,10 +39,6 @@ class PostDisapproval < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:user, :post]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:user, :post]
|
[:user, :post]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class PostFlag < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :reason, :status)
|
q = search_attributes(params, :id, :created_at, :updated_at, :reason, :status, :post)
|
||||||
q = q.text_attribute_matches(:reason, params[:reason_matches])
|
q = q.text_attribute_matches(:reason, params[:reason_matches])
|
||||||
|
|
||||||
if params[:creator_id].present?
|
if params[:creator_id].present?
|
||||||
@@ -111,10 +111,6 @@ class PostFlag < ApplicationRecord
|
|||||||
post.uploader_id
|
post.uploader_id
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:post]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:post]
|
[:post]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class PostReplacement < ApplicationRecord
|
|||||||
concerning :Search do
|
concerning :Search do
|
||||||
class_methods do
|
class_methods do
|
||||||
def search(params = {})
|
def search(params = {})
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :md5, :md5_was, :file_ext, :file_ext_was, :original_url, :replacement_url)
|
q = search_attributes(params, :id, :created_at, :updated_at, :md5, :md5_was, :file_ext, :file_ext_was, :original_url, :replacement_url, :creator, :post)
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -38,10 +38,6 @@ class PostReplacement < ApplicationRecord
|
|||||||
tags.join(" ")
|
tags.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:creator, :post]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:creator, :post]
|
[:creator, :post]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class PostVote < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :score)
|
q = search_attributes(params, :id, :created_at, :updated_at, :score, :user, :post)
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -49,10 +49,6 @@ class PostVote < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:user, :post]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:user, :post]
|
[:user, :post]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ class Tag < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_locked, :category, :post_count, :name)
|
q = search_attributes(params, :id, :created_at, :updated_at, :is_locked, :category, :post_count, :name, :wiki_page, :artist, :antecedent_alias, :consequent_aliases, :antecedent_implications, :consequent_implications, :dtext_links)
|
||||||
|
|
||||||
if params[:fuzzy_name_matches].present?
|
if params[:fuzzy_name_matches].present?
|
||||||
q = q.fuzzy_name_matches(params[:fuzzy_name_matches])
|
q = q.fuzzy_name_matches(params[:fuzzy_name_matches])
|
||||||
@@ -376,10 +376,6 @@ class Tag < ApplicationRecord
|
|||||||
super.where(table[:post_count].gt(0))
|
super.where(table[:post_count].gt(0))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:wiki_page, :artist, :antecedent_alias, :consequent_aliases, :antecedent_implications, :consequent_implications, :dtext_links]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:wiki_page, :artist, :antecedent_alias, :consequent_aliases, :antecedent_implications, :consequent_implications, :dtext_links]
|
[:wiki_page, :artist, :antecedent_alias, :consequent_aliases, :antecedent_implications, :consequent_implications, :dtext_links]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class TagRelationship < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :antecedent_name, :consequent_name)
|
q = search_attributes(params, :id, :created_at, :updated_at, :antecedent_name, :consequent_name, :creator, :approver, :forum_post, :forum_topic, :antecedent_tag, :consequent_tag, :antecedent_wiki, :consequent_wiki)
|
||||||
|
|
||||||
if params[:name_matches].present?
|
if params[:name_matches].present?
|
||||||
q = q.name_matches(params[:name_matches])
|
q = q.name_matches(params[:name_matches])
|
||||||
@@ -125,10 +125,6 @@ class TagRelationship < ApplicationRecord
|
|||||||
super.where(table[:status].eq("active"))
|
super.where(table[:status].eq("active"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:creator, :approver, :forum_post, :forum_topic, :antecedent_tag, :consequent_tag, :antecedent_wiki, :consequent_wiki]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:creator, :approver, :forum_post, :forum_topic, :antecedent_tag, :consequent_tag, :antecedent_wiki, :consequent_wiki]
|
[:creator, :approver, :forum_post, :forum_topic, :antecedent_tag, :consequent_tag, :antecedent_wiki, :consequent_wiki]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ class Upload < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :source, :rating, :parent_id, :server, :md5, :server, :file_ext, :file_size, :image_width, :image_height, :referer_url)
|
q = search_attributes(params, :id, :created_at, :updated_at, :source, :rating, :parent_id, :server, :md5, :server, :file_ext, :file_size, :image_width, :image_height, :referer_url, :uploader, :post)
|
||||||
|
|
||||||
if params[:source_matches].present?
|
if params[:source_matches].present?
|
||||||
q = q.where_like(:source, params[:source_matches])
|
q = q.where_like(:source, params[:source_matches])
|
||||||
@@ -223,10 +223,6 @@ class Upload < ApplicationRecord
|
|||||||
artist_commentary_title.present? || artist_commentary_desc.present? || translated_commentary_title.present? || translated_commentary_desc.present?
|
artist_commentary_title.present? || artist_commentary_desc.present? || translated_commentary_title.present? || translated_commentary_desc.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:uploader, :post]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:uploader, :post]
|
[:uploader, :post]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -563,7 +563,14 @@ class User < ApplicationRecord
|
|||||||
params = params.dup
|
params = params.dup
|
||||||
params[:name_matches] = params.delete(:name) if params[:name].present?
|
params[:name_matches] = params.delete(:name) if params[:name].present?
|
||||||
|
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :name, :level, :post_upload_count, :post_update_count, :note_update_count, :favorite_count)
|
q = search_attributes(params,
|
||||||
|
:id, :created_at, :updated_at, :name, :level, :post_upload_count,
|
||||||
|
:post_update_count, :note_update_count, :favorite_count, :posts,
|
||||||
|
:note_versions, :artist_commentary_versions, :post_appeals,
|
||||||
|
:post_approvals, :artist_versions, :comments, :wiki_page_versions,
|
||||||
|
:feedback, :forum_topics, :forum_posts, :forum_post_votes,
|
||||||
|
:tag_aliases, :tag_implications, :bans, :inviter
|
||||||
|
)
|
||||||
|
|
||||||
if params[:name_matches].present?
|
if params[:name_matches].present?
|
||||||
q = q.where_ilike(:name, normalize_name(params[:name_matches]))
|
q = q.where_ilike(:name, normalize_name(params[:name_matches]))
|
||||||
@@ -631,10 +638,6 @@ class User < ApplicationRecord
|
|||||||
"<@#{name}>"
|
"<@#{name}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:posts, :note_versions, :artist_commentary_versions, :post_appeals, :post_approvals, :artist_versions, :comments, :wiki_page_versions, :feedback, :forum_topics, :forum_posts, :forum_post_votes, :tag_aliases, :tag_implications, :bans, :inviter]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:inviter]
|
[:inviter]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class UserFeedback < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :category, :body, :is_deleted)
|
q = search_attributes(params, :id, :created_at, :updated_at, :category, :body, :is_deleted, :creator, :user)
|
||||||
q = q.text_attribute_matches(:body, params[:body_matches])
|
q = q.text_attribute_matches(:body, params[:body_matches])
|
||||||
|
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
@@ -56,10 +56,6 @@ class UserFeedback < ApplicationRecord
|
|||||||
Dmail.create_automated(:to_id => user_id, :title => "Your user record has been updated", :body => body)
|
Dmail.create_automated(:to_id => user_id, :title => "Your user record has been updated", :body => body)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:creator, :user]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:creator, :user]
|
[:creator, :user]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class WikiPage < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search(params = {})
|
def search(params = {})
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_locked, :is_deleted, :body, :title, :other_names)
|
q = search_attributes(params, :id, :created_at, :updated_at, :is_locked, :is_deleted, :body, :title, :other_names, :tag, :artist, :dtext_links)
|
||||||
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index, ts_config: "danbooru")
|
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index, ts_config: "danbooru")
|
||||||
|
|
||||||
if params[:title_normalize].present?
|
if params[:title_normalize].present?
|
||||||
@@ -246,10 +246,6 @@ class WikiPage < ApplicationRecord
|
|||||||
super.where(table[:is_deleted].eq(false))
|
super.where(table[:is_deleted].eq(false))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:tag, :artist, :dtext_links]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:tag, :artist, :dtext_links]
|
[:tag, :artist, :dtext_links]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class WikiPageVersion < ApplicationRecord
|
|||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def search(params)
|
def search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :title, :body, :other_names, :is_locked, :is_deleted)
|
q = search_attributes(params, :id, :created_at, :updated_at, :title, :body, :other_names, :is_locked, :is_deleted, :updater, :wiki_page, :artist, :tag)
|
||||||
q = q.text_attribute_matches(:title, params[:title_matches])
|
q = q.text_attribute_matches(:title, params[:title_matches])
|
||||||
q = q.text_attribute_matches(:body, params[:body_matches])
|
q = q.text_attribute_matches(:body, params[:body_matches])
|
||||||
|
|
||||||
@@ -75,10 +75,6 @@ class WikiPageVersion < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searchable_includes
|
|
||||||
[:updater, :wiki_page, :artist, :tag]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:updater, :wiki_page, :artist, :tag]
|
[:updater, :wiki_page, :artist, :tag]
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user