From ee4516f5fe6e665e98d64a0bdde48208a59d4afb Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 16 Dec 2020 22:43:18 -0600 Subject: [PATCH] searchable: refactor searchable_includes. Pass searchable associations directly to search_attributes instead of defining them separately in searchable_includes. --- app/logical/concerns/searchable.rb | 1 - app/models/application_record.rb | 4 ---- app/models/artist.rb | 6 +----- app/models/artist_commentary.rb | 6 +----- app/models/artist_commentary_version.rb | 6 +----- app/models/artist_url.rb | 6 +----- app/models/artist_version.rb | 6 +----- app/models/ban.rb | 6 +----- app/models/bulk_update_request.rb | 6 +----- app/models/comment.rb | 6 +----- app/models/comment_vote.rb | 6 +----- app/models/dmail.rb | 6 +----- app/models/dtext_link.rb | 6 +----- app/models/favorite_group.rb | 6 +----- app/models/forum_post.rb | 6 +----- app/models/forum_post_vote.rb | 6 +----- app/models/forum_topic.rb | 6 +----- app/models/ip_address.rb | 6 +----- app/models/ip_ban.rb | 6 +----- app/models/mod_action.rb | 6 +----- app/models/moderation_report.rb | 6 +----- app/models/note.rb | 6 +----- app/models/note_version.rb | 6 +----- app/models/pixiv_ugoira_frame_data.rb | 6 +----- app/models/post.rb | 9 ++++----- app/models/post_appeal.rb | 6 +----- app/models/post_approval.rb | 6 +----- app/models/post_disapproval.rb | 6 +----- app/models/post_flag.rb | 6 +----- app/models/post_replacement.rb | 6 +----- app/models/post_vote.rb | 6 +----- app/models/tag.rb | 6 +----- app/models/tag_relationship.rb | 6 +----- app/models/upload.rb | 6 +----- app/models/user.rb | 13 ++++++++----- app/models/user_feedback.rb | 6 +----- app/models/wiki_page.rb | 6 +----- app/models/wiki_page_version.rb | 6 +----- 38 files changed, 46 insertions(+), 185 deletions(-) diff --git a/app/logical/concerns/searchable.rb b/app/logical/concerns/searchable.rb index 321d89a81..cac920cc8 100644 --- a/app/logical/concerns/searchable.rb +++ b/app/logical/concerns/searchable.rb @@ -155,7 +155,6 @@ module Searchable indifferent_params = params.try(:with_indifferent_access) || params.try(:to_unsafe_h) raise ArgumentError, "unable to process params" if indifferent_params.nil? - attributes += searchable_includes attributes.reduce(all) do |relation, attribute| relation.search_attribute(attribute, indifferent_params, CurrentUser.user) end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index c65ae40d1..e162b39dd 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -93,10 +93,6 @@ class ApplicationRecord < ActiveRecord::Base concerning :SearchMethods do class_methods do - def searchable_includes - [] - end - def model_restriction(table) table.project(1) end diff --git a/app/models/artist.rb b/app/models/artist.rb index 9ee09c407..56f1baee8 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -250,7 +250,7 @@ class Artist < ApplicationRecord end 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] 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)) end - def self.searchable_includes - [:urls, :wiki_page, :tag_alias, :tag] - end - def self.available_includes [:members, :urls, :wiki_page, :tag_alias, :tag] end diff --git a/app/models/artist_commentary.rb b/app/models/artist_commentary.rb index 1ea297c62..d1b5bcee6 100644 --- a/app/models/artist_commentary.rb +++ b/app/models/artist_commentary.rb @@ -31,7 +31,7 @@ class ArtistCommentary < ApplicationRecord end 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? q = q.text_matches(params[:text_matches]) @@ -144,10 +144,6 @@ class ArtistCommentary < ApplicationRecord extend SearchMethods include VersionMethods - def self.searchable_includes - [:post] - end - def self.available_includes [:post] end diff --git a/app/models/artist_commentary_version.rb b/app/models/artist_commentary_version.rb index c9fcb9a49..0b4c00436 100644 --- a/app/models/artist_commentary_version.rb +++ b/app/models/artist_commentary_version.rb @@ -12,7 +12,7 @@ class ArtistCommentaryVersion < ApplicationRecord end 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? q = q.text_matches(params[:text_matches]) @@ -55,10 +55,6 @@ class ArtistCommentaryVersion < ApplicationRecord self[field].strip.empty? && (previous.nil? || previous[field].strip.empty?) end - def self.searchable_includes - [:post, :updater] - end - def self.available_includes [:post, :updater] end diff --git a/app/models/artist_url.rb b/app/models/artist_url.rb index bd17c7358..fa9b359fb 100644 --- a/app/models/artist_url.rb +++ b/app/models/artist_url.rb @@ -40,7 +40,7 @@ class ArtistUrl < ApplicationRecord end 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.normalized_url_matches(params[:normalized_url_matches]) @@ -126,10 +126,6 @@ class ArtistUrl < ApplicationRecord errors.add(:url, "'#{uri}' is malformed: #{error}") end - def self.searchable_includes - [:artist] - end - def self.available_includes [:artist] end diff --git a/app/models/artist_version.rb b/app/models/artist_version.rb index c7af5690a..a743c43ed 100644 --- a/app/models/artist_version.rb +++ b/app/models/artist_version.rb @@ -7,7 +7,7 @@ class ArtistVersion < ApplicationRecord module SearchMethods 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(:group_name, params[:group_name_matches]) @@ -103,10 +103,6 @@ class ArtistVersion < ApplicationRecord end end - def self.searchable_includes - [:updater, :artist] - end - def self.available_includes [:updater, :artist] end diff --git a/app/models/ban.rb b/app/models/ban.rb index 6417ba739..c641b4d5a 100644 --- a/app/models/ban.rb +++ b/app/models/ban.rb @@ -20,7 +20,7 @@ class Ban < ApplicationRecord end 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.expired if params[:expired].to_s.truthy? @@ -87,10 +87,6 @@ class Ban < ApplicationRecord ModAction.log(%{Unbanned <@#{user_name}>}, :user_unban) end - def self.searchable_includes - [:user, :banner] - end - def self.available_includes [:user, :banner] end diff --git a/app/models/bulk_update_request.rb b/app/models/bulk_update_request.rb index a189fe72a..d7afa226d 100644 --- a/app/models/bulk_update_request.rb +++ b/app/models/bulk_update_request.rb @@ -31,7 +31,7 @@ class BulkUpdateRequest < ApplicationRecord end 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]) if params[:status].present? @@ -126,10 +126,6 @@ class BulkUpdateRequest < ApplicationRecord status == "rejected" end - def self.searchable_includes - [:user, :forum_topic, :forum_post, :approver] - end - def self.available_includes [:user, :forum_topic, :forum_post, :approver] end diff --git a/app/models/comment.rb b/app/models/comment.rb index 71f23b698..2207706ef 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -26,7 +26,7 @@ class Comment < ApplicationRecord module SearchMethods 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) case params[:order] @@ -137,10 +137,6 @@ class Comment < ApplicationRecord DText.quote(body, creator.name) end - def self.searchable_includes - [:post, :creator, :updater] - end - def self.available_includes [:post, :creator, :updater] end diff --git a/app/models/comment_vote.rb b/app/models/comment_vote.rb index bb1fa3ca8..b87642d10 100644 --- a/app/models/comment_vote.rb +++ b/app/models/comment_vote.rb @@ -19,7 +19,7 @@ class CommentVote < ApplicationRecord end 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) end @@ -37,10 +37,6 @@ class CommentVote < ApplicationRecord score == -1 end - def self.searchable_includes - [:comment, :user] - end - def self.available_includes [:comment, :user] end diff --git a/app/models/dmail.rb b/app/models/dmail.rb index a5c945f89..63094bff5 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -98,7 +98,7 @@ class Dmail < ApplicationRecord end 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(:body, params[:message_matches], index_column: :message_index) @@ -180,10 +180,6 @@ class Dmail < ApplicationRecord key ? "dmail ##{id}/#{self.key}" : "dmail ##{id}" end - def self.searchable_includes - [:to, :from] - end - def self.available_includes [:owner, :to, :from] end diff --git a/app/models/dtext_link.rb b/app/models/dtext_link.rb index 9be3cc6b3..3d3f8d62b 100644 --- a/app/models/dtext_link.rb +++ b/app/models/dtext_link.rb @@ -30,7 +30,7 @@ class DtextLink < ApplicationRecord end 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) end @@ -48,10 +48,6 @@ class DtextLink < ApplicationRecord where(link_type: :wiki_link) end - def self.searchable_includes - [:model, :linked_wiki, :linked_tag] - end - def self.available_includes [:model, :linked_wiki, :linked_tag] end diff --git a/app/models/favorite_group.rb b/app/models/favorite_group.rb index 45040b79f..5a0c07190 100644 --- a/app/models/favorite_group.rb +++ b/app/models/favorite_group.rb @@ -26,7 +26,7 @@ class FavoriteGroup < ApplicationRecord end 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? q = q.name_matches(params[:name_matches]) @@ -163,10 +163,6 @@ class FavoriteGroup < ApplicationRecord post_ids.include?(post_id) end - def self.searchable_includes - [:creator] - end - def self.available_includes [:creator] end diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 0d05876b2..c8aad7962 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -41,7 +41,7 @@ class ForumPost < ApplicationRecord end 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) if params[:linked_to].present? @@ -163,10 +163,6 @@ class ForumPost < ApplicationRecord "forum ##{id}" end - def self.searchable_includes - [:creator, :updater, :topic, :dtext_links, :votes, :tag_alias, :tag_implication, :bulk_update_request] - end - def self.available_includes [:creator, :updater, :topic, :dtext_links, :votes, :tag_alias, :tag_implication, :bulk_update_request] end diff --git a/app/models/forum_post_vote.rb b/app/models/forum_post_vote.rb index 7e36cd879..6a2ac7926 100644 --- a/app/models/forum_post_vote.rb +++ b/app/models/forum_post_vote.rb @@ -19,7 +19,7 @@ class ForumPostVote < ApplicationRecord end 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.apply_default_order(params) end @@ -58,10 +58,6 @@ class ForumPostVote < ApplicationRecord end end - def self.searchable_includes - [:creator, :forum_post] - end - def self.available_includes [:creator, :forum_post] end diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index f70a02af6..0ab60d042 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -86,7 +86,7 @@ class ForumTopic < ApplicationRecord end 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) if params[:is_private].to_s.truthy? @@ -189,10 +189,6 @@ class ForumTopic < ApplicationRecord title.gsub(/\A\[APPROVED\]|\[REJECTED\]/, "") end - def self.searchable_includes - [:creator, :updater, :forum_posts, :bulk_update_requests, :tag_aliases, :tag_implications] - end - def self.available_includes [:creator, :updater, :original_post] end diff --git a/app/models/ip_address.rb b/app/models/ip_address.rb index 0e286f7f4..77f44b3ff 100644 --- a/app/models/ip_address.rb +++ b/app/models/ip_address.rb @@ -12,7 +12,7 @@ class IpAddress < ApplicationRecord end def self.search(params) - q = search_attributes(params, :ip_addr) + q = search_attributes(params, :ip_addr, :user, :model) q.order(created_at: :desc) end @@ -49,10 +49,6 @@ class IpAddress < ApplicationRecord true end - def self.searchable_includes - [:user, :model] - end - def self.available_includes [:user, :model] end diff --git a/app/models/ip_ban.rb b/app/models/ip_ban.rb index 1182bef54..223539f43 100644 --- a/app/models/ip_ban.rb +++ b/app/models/ip_ban.rb @@ -25,7 +25,7 @@ class IpBan < ApplicationRecord end 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]) if params[:ip_addr].present? @@ -77,10 +77,6 @@ class IpBan < ApplicationRecord super(ip_addr.strip) end - def self.searchable_includes - [:creator] - end - def self.available_includes [:creator] end diff --git a/app/models/mod_action.rb b/app/models/mod_action.rb index 7d0b73615..437d3efea 100644 --- a/app/models/mod_action.rb +++ b/app/models/mod_action.rb @@ -61,7 +61,7 @@ class ModAction < ApplicationRecord end 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.apply_default_order(params) @@ -75,10 +75,6 @@ class ModAction < ApplicationRecord create(creator: user, description: desc, category: categories[cat]) end - def self.searchable_includes - [:creator] - end - def self.available_includes [:creator] end diff --git a/app/models/moderation_report.rb b/app/models/moderation_report.rb index 9916154cd..20874e2d1 100644 --- a/app/models/moderation_report.rb +++ b/app/models/moderation_report.rb @@ -82,16 +82,12 @@ class ModerationReport < ApplicationRecord end 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.apply_default_order(params) end - def self.searchable_includes - [:creator, :model] - end - def self.available_includes [:creator, :model] end diff --git a/app/models/note.rb b/app/models/note.rb index 431161e5f..f2cc46ed3 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -14,7 +14,7 @@ class Note < ApplicationRecord module SearchMethods 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.apply_default_order(params) @@ -127,10 +127,6 @@ class Note < ApplicationRecord new_note.save end - def self.searchable_includes - [:post] - end - def self.available_includes [:post] end diff --git a/app/models/note_version.rb b/app/models/note_version.rb index 310e0ef16..2b973650f 100644 --- a/app/models/note_version.rb +++ b/app/models/note_version.rb @@ -4,7 +4,7 @@ class NoteVersion < ApplicationRecord belongs_to_updater :counter_cache => "note_update_count" 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.apply_default_order(params) @@ -69,10 +69,6 @@ class NoteVersion < ApplicationRecord end end - def self.searchable_includes - [:updater, :note, :post] - end - def self.available_includes [:updater, :note, :post] end diff --git a/app/models/pixiv_ugoira_frame_data.rb b/app/models/pixiv_ugoira_frame_data.rb index 8c35a9387..bbb5a5498 100644 --- a/app/models/pixiv_ugoira_frame_data.rb +++ b/app/models/pixiv_ugoira_frame_data.rb @@ -4,16 +4,12 @@ class PixivUgoiraFrameData < ApplicationRecord serialize :data before_validation :normalize_data, on: :create - def self.searchable_includes - [:post] - end - def self.available_includes [:post] end 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) end diff --git a/app/models/post.rb b/app/models/post.rb index e4f1b5afe..9fd75b7ad 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1296,7 +1296,10 @@ class Post < ApplicationRecord :image_height, :tag_count, :has_children, :has_active_children, :is_note_locked, :is_rating_locked, :is_status_locked, :is_pending, :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? @@ -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)) 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 [:uploader, :updater, :approver, :parent, :upload, :artist_commentary, :flags, :appeals, :notes, :comments, :children, :approvals, :replacements, :pixiv_ugoira_frame_data] end diff --git a/app/models/post_appeal.rb b/app/models/post_appeal.rb index e8049e88c..e7ce3d069 100644 --- a/app/models/post_appeal.rb +++ b/app/models/post_appeal.rb @@ -17,7 +17,7 @@ class PostAppeal < ApplicationRecord module SearchMethods 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.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? end - def self.searchable_includes - [:creator, :post] - end - def self.available_includes [:creator, :post] end diff --git a/app/models/post_approval.rb b/app/models/post_approval.rb index 127d49958..1b95b619c 100644 --- a/app/models/post_approval.rb +++ b/app/models/post_approval.rb @@ -38,14 +38,10 @@ class PostApproval < ApplicationRecord end 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) end - def self.searchable_includes - [:user, :post] - end - def self.available_includes [:user, :post] end diff --git a/app/models/post_disapproval.rb b/app/models/post_disapproval.rb index f08d318c9..eccf6f41c 100644 --- a/app/models/post_disapproval.rb +++ b/app/models/post_disapproval.rb @@ -21,7 +21,7 @@ class PostDisapproval < ApplicationRecord concerning :SearchMethods do class_methods do 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.with_message if params[:has_message].to_s.truthy? @@ -39,10 +39,6 @@ class PostDisapproval < ApplicationRecord end end - def self.searchable_includes - [:user, :post] - end - def self.available_includes [:user, :post] end diff --git a/app/models/post_flag.rb b/app/models/post_flag.rb index 3254f073c..647d852ed 100644 --- a/app/models/post_flag.rb +++ b/app/models/post_flag.rb @@ -56,7 +56,7 @@ class PostFlag < ApplicationRecord end 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]) if params[:creator_id].present? @@ -111,10 +111,6 @@ class PostFlag < ApplicationRecord post.uploader_id end - def self.searchable_includes - [:post] - end - def self.available_includes [:post] end diff --git a/app/models/post_replacement.rb b/app/models/post_replacement.rb index 04e80a78d..ae5a23174 100644 --- a/app/models/post_replacement.rb +++ b/app/models/post_replacement.rb @@ -21,7 +21,7 @@ class PostReplacement < ApplicationRecord concerning :Search do class_methods do 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) end end @@ -38,10 +38,6 @@ class PostReplacement < ApplicationRecord tags.join(" ") end - def self.searchable_includes - [:creator, :post] - end - def self.available_includes [:creator, :post] end diff --git a/app/models/post_vote.rb b/app/models/post_vote.rb index 096b123df..ab8ea1090 100644 --- a/app/models/post_vote.rb +++ b/app/models/post_vote.rb @@ -19,7 +19,7 @@ class PostVote < ApplicationRecord end 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) end @@ -49,10 +49,6 @@ class PostVote < ApplicationRecord end end - def self.searchable_includes - [:user, :post] - end - def self.available_includes [:user, :post] end diff --git a/app/models/tag.rb b/app/models/tag.rb index 86fd3fb1e..27255bed9 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -271,7 +271,7 @@ class Tag < ApplicationRecord end 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? q = q.fuzzy_name_matches(params[:fuzzy_name_matches]) @@ -376,10 +376,6 @@ class Tag < ApplicationRecord super.where(table[:post_count].gt(0)) end - def self.searchable_includes - [:wiki_page, :artist, :antecedent_alias, :consequent_aliases, :antecedent_implications, :consequent_implications, :dtext_links] - end - def self.available_includes [:wiki_page, :artist, :antecedent_alias, :consequent_aliases, :antecedent_implications, :consequent_implications, :dtext_links] end diff --git a/app/models/tag_relationship.rb b/app/models/tag_relationship.rb index 1d303b6e7..28e6bacb1 100644 --- a/app/models/tag_relationship.rb +++ b/app/models/tag_relationship.rb @@ -66,7 +66,7 @@ class TagRelationship < ApplicationRecord end 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? q = q.name_matches(params[:name_matches]) @@ -125,10 +125,6 @@ class TagRelationship < ApplicationRecord super.where(table[:status].eq("active")) end - def self.searchable_includes - [:creator, :approver, :forum_post, :forum_topic, :antecedent_tag, :consequent_tag, :antecedent_wiki, :consequent_wiki] - end - def self.available_includes [:creator, :approver, :forum_post, :forum_topic, :antecedent_tag, :consequent_tag, :antecedent_wiki, :consequent_wiki] end diff --git a/app/models/upload.rb b/app/models/upload.rb index 383c59a65..6c2878076 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -182,7 +182,7 @@ class Upload < ApplicationRecord end 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? 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? end - def self.searchable_includes - [:uploader, :post] - end - def self.available_includes [:uploader, :post] end diff --git a/app/models/user.rb b/app/models/user.rb index ee0603a16..c56a19adb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -563,7 +563,14 @@ class User < ApplicationRecord params = params.dup 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? q = q.where_ilike(:name, normalize_name(params[:name_matches])) @@ -631,10 +638,6 @@ class User < ApplicationRecord "<@#{name}>" 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 [:inviter] end diff --git a/app/models/user_feedback.rb b/app/models/user_feedback.rb index f52d0d856..cda52916c 100644 --- a/app/models/user_feedback.rb +++ b/app/models/user_feedback.rb @@ -30,7 +30,7 @@ class UserFeedback < ApplicationRecord end 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.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) end - def self.searchable_includes - [:creator, :user] - end - def self.available_includes [:creator, :user] end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index f92a0936e..3b0b28045 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -65,7 +65,7 @@ class WikiPage < ApplicationRecord end 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") if params[:title_normalize].present? @@ -246,10 +246,6 @@ class WikiPage < ApplicationRecord super.where(table[:is_deleted].eq(false)) end - def self.searchable_includes - [:tag, :artist, :dtext_links] - end - def self.available_includes [:tag, :artist, :dtext_links] end diff --git a/app/models/wiki_page_version.rb b/app/models/wiki_page_version.rb index 264474951..1f405d4f1 100644 --- a/app/models/wiki_page_version.rb +++ b/app/models/wiki_page_version.rb @@ -7,7 +7,7 @@ class WikiPageVersion < ApplicationRecord module SearchMethods 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(:body, params[:body_matches]) @@ -75,10 +75,6 @@ class WikiPageVersion < ApplicationRecord end end - def self.searchable_includes - [:updater, :wiki_page, :artist, :tag] - end - def self.available_includes [:updater, :wiki_page, :artist, :tag] end