diff --git a/app/models/artist.rb b/app/models/artist.rb index e40820fef..dccde5f68 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -266,12 +266,6 @@ class Artist < ApplicationRecord q = q.url_matches(params[:url_matches]) end - if params[:has_tag].to_s.truthy? - q = q.where(name: Tag.nonempty.select(:name)) - elsif params[:has_tag].to_s.falsy? - q = q.where.not(name: Tag.nonempty.select(:name)) - end - case params[:order] when "name" q = q.order("artists.name") @@ -295,6 +289,14 @@ class Artist < ApplicationRecord include BanMethods extend SearchMethods + def self.model_restriction(table) + 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 64cf215a9..d94939d22 100644 --- a/app/models/artist_commentary.rb +++ b/app/models/artist_commentary.rb @@ -33,7 +33,7 @@ class ArtistCommentary < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :post, :original_title, :original_description, :translated_title, :translated_description) + q = q.search_attributes(params, :original_title, :original_description, :translated_title, :translated_description) if params[:text_matches].present? q = q.text_matches(params[:text_matches]) @@ -146,6 +146,10 @@ 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 d052810e8..32c59ac85 100644 --- a/app/models/artist_commentary_version.rb +++ b/app/models/artist_commentary_version.rb @@ -4,7 +4,7 @@ class ArtistCommentaryVersion < ApplicationRecord def self.search(params) q = super - q = q.search_attributes(params, :post, :updater, :original_title, :original_description, :translated_title, :translated_description) + q = q.search_attributes(params, :original_title, :original_description, :translated_title, :translated_description) q.apply_default_order(params) end @@ -42,6 +42,10 @@ 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 b4e4d9af5..1119305a5 100644 --- a/app/models/artist_url.rb +++ b/app/models/artist_url.rb @@ -42,9 +42,8 @@ class ArtistUrl < ApplicationRecord def self.search(params = {}) q = super - q = q.search_attributes(params, :url, :normalized_url, :artist_id, :is_active) + q = q.search_attributes(params, :url, :normalized_url, :is_active) - q = q.artist_matches(params[:artist]) q = q.url_matches(params[:url_matches]) q = q.normalized_url_matches(params[:normalized_url_matches]) @@ -59,11 +58,6 @@ class ArtistUrl < ApplicationRecord q end - def self.artist_matches(params = {}) - return all if params.blank? - where(artist_id: Artist.search(params).reorder(nil)) - end - def self.url_attribute_matches(attr, url) if url.blank? all @@ -134,6 +128,10 @@ class ArtistUrl < ApplicationRecord errors[: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 bcd08fa2b..529e8e4e6 100644 --- a/app/models/artist_version.rb +++ b/app/models/artist_version.rb @@ -9,7 +9,7 @@ class ArtistVersion < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :updater, :is_deleted, :is_banned, :artist_id, :name, :group_name) + q = q.search_attributes(params, :is_deleted, :is_banned, :name, :group_name) if params[:order] == "name" q = q.order("artist_versions.name").default_order @@ -103,6 +103,10 @@ 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 8c7530ac7..3cedce4b8 100644 --- a/app/models/ban.rb +++ b/app/models/ban.rb @@ -18,7 +18,7 @@ class Ban < ApplicationRecord def self.search(params) q = super - q = q.search_attributes(params, :banner, :user, :expires_at, :reason) + q = q.search_attributes(params, :expires_at, :reason) q = q.text_attribute_matches(:reason, params[:reason_matches]) q = q.expired if params[:expired].to_s.truthy? @@ -91,6 +91,10 @@ 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 6909728a6..2070dc1db 100644 --- a/app/models/bulk_update_request.rb +++ b/app/models/bulk_update_request.rb @@ -35,7 +35,7 @@ class BulkUpdateRequest < ApplicationRecord def search(params = {}) q = super - q = q.search_attributes(params, :user, :approver, :forum_topic_id, :forum_post_id, :script, :tags) + q = q.search_attributes(params, :script, :tags) q = q.text_attribute_matches(:script, params[:script_matches]) if params[:status].present? @@ -152,6 +152,10 @@ 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 a402fcbc2..ade9a8073 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -28,7 +28,7 @@ class Comment < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :post, :creator, :updater, :is_deleted, :is_sticky, :do_not_bump_post, :body, :score) + q = q.search_attributes(params, :is_deleted, :is_sticky, :do_not_bump_post, :body, :score) q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index) case params[:order] @@ -140,6 +140,10 @@ 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 0cfea7c16..ec1a5ce11 100644 --- a/app/models/comment_vote.rb +++ b/app/models/comment_vote.rb @@ -18,15 +18,9 @@ class CommentVote < ApplicationRecord end end - def self.comment_matches(params) - return all if params.blank? - where(comment_id: Comment.search(params).reorder(nil).select(:id)) - end - def self.search(params) q = super - q = q.search_attributes(params, :comment_id, :user, :score) - q = q.comment_matches(params[:comment]) + q = q.search_attributes(params, :score) q.apply_default_order(params) end @@ -44,6 +38,10 @@ 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 25c053213..54b167242 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -98,7 +98,7 @@ class Dmail < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :to, :from, :is_read, :is_deleted, :title, :body) + q = q.search_attributes(params, :is_read, :is_deleted, :title, :body) q = q.text_attribute_matches(:title, params[:title_matches]) q = q.text_attribute_matches(:body, params[:message_matches], index_column: :message_index) @@ -172,6 +172,10 @@ 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 08df3bc23..85246eb53 100644 --- a/app/models/dtext_link.rb +++ b/app/models/dtext_link.rb @@ -28,43 +28,9 @@ class DtextLink < ApplicationRecord links end - def self.model_matches(params) - return all if params.blank? - where(model_type: "WikiPage", model_id: WikiPage.search(params).reorder(nil)) - end - - def self.linked_wiki_exists(exists = true) - dtext_links = DtextLink.arel_table - wiki_pages = WikiPage.arel_table - wiki_exists = wiki_pages.project(1).where(wiki_pages[:is_deleted].eq(false)).where(wiki_pages[:title].eq(dtext_links[:link_target])).exists - - if exists - where(link_type: :wiki_link).where(wiki_exists) - else - where(link_type: :wiki_link).where.not(wiki_exists) - end - end - - def self.linked_tag_exists(exists = true) - dtext_links = DtextLink.arel_table - tags = Tag.arel_table - tag_exists = tags.project(1).where(tags[:post_count].gt(0)).where(tags[:name].eq(dtext_links[:link_target])).exists - - if exists - where(link_type: :wiki_link).where(tag_exists) - else - where(link_type: :wiki_link).where.not(tag_exists) - end - end - def self.search(params) q = super - q = q.search_attributes(params, :model_type, :model_id, :link_type, :link_target) - - q = q.model_matches(params[:model]) - q = q.linked_wiki_exists(params[:linked_wiki_exists].truthy?) if params[:linked_wiki_exists].present? - q = q.linked_tag_exists(params[:linked_tag_exists].truthy?) if params[:linked_tag_exists].present? - + q = q.search_attributes(params, :link_type, :link_target) q.apply_default_order(params) end @@ -78,7 +44,15 @@ class DtextLink < ApplicationRecord self.link_target = self.link_target.truncate(2048, omission: "") end + def self.attribute_restriction(*) + where(link_type: :wiki_link) + end + + def self.searchable_includes + [:model, :linked_wiki] + end + def self.available_includes - [:model] + [:model, :linked_wiki] end end diff --git a/app/models/favorite_group.rb b/app/models/favorite_group.rb index d90e0e04a..edd4d0dfe 100644 --- a/app/models/favorite_group.rb +++ b/app/models/favorite_group.rb @@ -27,7 +27,7 @@ class FavoriteGroup < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :name, :is_public, :post_ids, :creator) + q = q.search_attributes(params, :name, :is_public, :post_ids) if params[:name_matches].present? q = q.name_matches(params[:name_matches]) @@ -164,6 +164,10 @@ 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 fde386242..d82c7b15f 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -32,31 +32,19 @@ class ForumPost < ApplicationRecord ) module SearchMethods - def topic_title_matches(title) - where(topic_id: ForumTopic.search(title_matches: title).select(:id)) - end - def visible(user) where(topic_id: ForumTopic.visible(user)) end def search(params) q = super - q = q.search_attributes(params, :creator, :updater, :topic_id, :is_deleted, :body) + q = q.search_attributes(params, :is_deleted, :body) q = q.text_attribute_matches(:body, params[:body_matches], index_column: :text_index) if params[:linked_to].present? q = q.where(id: DtextLink.forum_post.wiki_link.where(link_target: params[:linked_to]).select(:model_id)) end - if params[:topic_title_matches].present? - q = q.topic_title_matches(params[:topic_title_matches]) - end - - if params[:topic_category_id].present? - q = q.where(topic_id: ForumTopic.where(category_id: params[:topic_category_id])) - end - q.apply_default_order(params) end end @@ -179,6 +167,10 @@ 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 fe2bcd77c..3ea592389 100644 --- a/app/models/forum_post_vote.rb +++ b/app/models/forum_post_vote.rb @@ -20,7 +20,7 @@ class ForumPostVote < ApplicationRecord def self.search(params) q = super - q = q.search_attributes(params, :creator, :forum_post_id, :score) + q = q.search_attributes(params, :score) q = q.forum_post_matches(params[:forum_post]) q.apply_default_order(params) end @@ -59,7 +59,11 @@ class ForumPostVote < ApplicationRecord end end + def self.searchable_includes + [:creator, :forum_post] + end + def self.available_includes - [:creator] + [:creator, :forum_post] end end diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index 22858c7f8..f934189ec 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -85,7 +85,7 @@ class ForumTopic < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :creator, :updater, :is_sticky, :is_locked, :is_deleted, :category_id, :title, :response_count) + q = q.search_attributes(params, :is_sticky, :is_locked, :is_deleted, :category_id, :title, :response_count) q = q.text_attribute_matches(:title, params[:title_matches], index_column: :text_index) if params[:is_private].to_s.truthy? @@ -190,6 +190,10 @@ class ForumTopic < ApplicationRecord super + [:is_read?] end + def self.searchable_includes + [:creator, :updater, :forum_posts, :bulk_update_requests] + 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 0fcf5a8fb..00920ced7 100644 --- a/app/models/ip_address.rb +++ b/app/models/ip_address.rb @@ -13,7 +13,7 @@ class IpAddress < ApplicationRecord def self.search(params) q = super - q = q.search_attributes(params, :user, :model_type, :model_id, :ip_addr) + q = q.search_attributes(params, :ip_addr) q.order(created_at: :desc) end @@ -54,6 +54,10 @@ class IpAddress < ApplicationRecord super & attributes.keys.map(&:to_sym) 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 7772250fa..4c4045c8f 100644 --- a/app/models/ip_ban.rb +++ b/app/models/ip_ban.rb @@ -26,7 +26,7 @@ class IpBan < ApplicationRecord def self.search(params) q = super - q = q.search_attributes(params, :creator, :reason) + q = q.search_attributes(params, :reason) if params[:ip_addr].present? q = q.where("ip_addr = ?", params[:ip_addr]) @@ -77,6 +77,10 @@ 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 73b3f58f9..430948648 100644 --- a/app/models/mod_action.rb +++ b/app/models/mod_action.rb @@ -63,7 +63,7 @@ class ModAction < ApplicationRecord def self.search(params) q = super - q = q.search_attributes(params, :creator, :category, :description) + q = q.search_attributes(params, :category, :description) q = q.text_attribute_matches(:description, params[:description_matches]) q.apply_default_order(params) @@ -77,6 +77,10 @@ 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 b45a6d86c..dd22848c1 100644 --- a/app/models/moderation_report.rb +++ b/app/models/moderation_report.rb @@ -83,11 +83,15 @@ class ModerationReport < ApplicationRecord def self.search(params) q = super - q = q.search_attributes(params, :model_type, :model_id, :creator_id) + q = q.search_attributes(params, :reason) 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 9dd89362e..4facb2028 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -16,7 +16,7 @@ class Note < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :post, :is_active, :x, :y, :width, :height, :body, :version) + q = q.search_attributes(params, :is_active, :x, :y, :width, :height, :body, :version) q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index) q.apply_default_order(params) @@ -129,6 +129,10 @@ 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 d8655f995..d8c3aed07 100644 --- a/app/models/note_version.rb +++ b/app/models/note_version.rb @@ -6,7 +6,7 @@ class NoteVersion < ApplicationRecord def self.search(params) q = super - q = q.search_attributes(params, :updater, :is_active, :post, :note_id, :x, :y, :width, :height, :body, :version) + q = q.search_attributes(params, :is_active, :x, :y, :width, :height, :body, :version) q = q.text_attribute_matches(:body, params[:body_matches]) q.apply_default_order(params) @@ -71,6 +71,10 @@ 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 2bfe5af3d..92c1eba2b 100644 --- a/app/models/pixiv_ugoira_frame_data.rb +++ b/app/models/pixiv_ugoira_frame_data.rb @@ -4,13 +4,17 @@ 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 = super - q = q.search_attributes(params, :post, :data, :content_type) + q = q.search_attributes(params, :data, :content_type) q.apply_default_order(params) end diff --git a/app/models/post.rb b/app/models/post.rb index 1d2121e50..c1ad711b6 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1296,12 +1296,12 @@ class Post < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, - :approver, :uploader, :rating, :source, :pixiv_id, :fav_count, :score, :up_score, - :down_score, :md5, :file_ext, :file_size, :image_width, :image_height, :tag_count, - :parent, :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 + q = q.search_attributes( + params, + :rating, :source, :pixiv_id, :fav_count, :score, :up_score, :down_score, :md5, :file_ext, + :file_size, :image_width, :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 ) if params[:tags].present? @@ -1513,6 +1513,14 @@ class Post < ApplicationRecord super + [:has_large?, :current_image_size] end + def self.model_restriction(table) + 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 d758f945f..a015d57fd 100644 --- a/app/models/post_appeal.rb +++ b/app/models/post_appeal.rb @@ -18,7 +18,7 @@ class PostAppeal < ApplicationRecord module SearchMethods def search(params) q = super - q = q.search_attributes(params, :creator, :post, :reason) + q = q.search_attributes(params, :reason) q = q.text_attribute_matches(:reason, params[:reason_matches]) q = q.resolved if params[:is_resolved].to_s.truthy? @@ -54,6 +54,10 @@ class PostAppeal < ApplicationRecord creator.post_appeals.recent.count 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 2981143d2..17ba4567a 100644 --- a/app/models/post_approval.rb +++ b/app/models/post_approval.rb @@ -37,10 +37,13 @@ class PostApproval < ApplicationRecord def self.search(params) q = super - q = q.search_attributes(params, :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 bf00344fe..07681f9e8 100644 --- a/app/models/post_disapproval.rb +++ b/app/models/post_disapproval.rb @@ -23,7 +23,7 @@ class PostDisapproval < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :post, :user, :message, :reason) + q = q.search_attributes(params, :message, :reason) q = q.text_attribute_matches(:message, params[:message_matches]) q = q.with_message if params[:has_message].to_s.truthy? @@ -41,6 +41,10 @@ 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 ff928bbee..34ce59405 100644 --- a/app/models/post_flag.rb +++ b/app/models/post_flag.rb @@ -56,7 +56,7 @@ class PostFlag < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :post, :is_resolved, :reason) + q = q.search_attributes(params, :is_resolved, :reason) q = q.text_attribute_matches(:reason, params[:reason_matches]) if params[:creator_id].present? @@ -129,6 +129,10 @@ 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 40cbaed2d..35dd266a6 100644 --- a/app/models/post_replacement.rb +++ b/app/models/post_replacement.rb @@ -22,7 +22,7 @@ class PostReplacement < ApplicationRecord class_methods do def search(params = {}) q = super - q = q.search_attributes(params, :post, :creator, :md5, :md5_was, :file_ext, :file_ext_was, :original_url, :replacement_url) + q = q.search_attributes(params, :md5, :md5_was, :file_ext, :file_ext_was, :original_url, :replacement_url) q.apply_default_order(params) end end @@ -39,6 +39,10 @@ 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 bcbcc74a2..e1dd75fa4 100644 --- a/app/models/post_vote.rb +++ b/app/models/post_vote.rb @@ -20,7 +20,7 @@ class PostVote < ApplicationRecord def self.search(params) q = super - q = q.search_attributes(params, :post, :user, :score) + q = q.search_attributes(params, :score) q.apply_default_order(params) end @@ -50,6 +50,10 @@ 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 2dc756445..7860d0913 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -286,18 +286,6 @@ class Tag < ApplicationRecord q = q.nonempty end - if params[:has_wiki].to_s.truthy? - q = q.joins(:wiki_page).merge(WikiPage.undeleted) - elsif params[:has_wiki].to_s.falsy? - q = q.left_outer_joins(:wiki_page).where("wiki_pages.title IS NULL OR wiki_pages.is_deleted = TRUE") - end - - if params[:has_artist].to_s.truthy? - q = q.joins(:artist).merge(Artist.undeleted) - elsif params[:has_artist].to_s.falsy? - q = q.left_outer_joins(:artist).where("artists.name IS NULL OR artists.is_deleted = TRUE") - end - case params[:order] when "name" q = q.order("name") @@ -357,6 +345,14 @@ class Tag < ApplicationRecord Post.system_tag_match(name) end + def self.model_restriction(table) + super.where(table[:post_count].gt(0)) + end + + def self.searchable_includes + [:wiki_page, :artist, :antecedent_alias, :consequent_aliases, :antecedent_implications, :consequent_implications] + end + def self.available_includes [:wiki_page, :artist, :antecedent_alias, :consequent_aliases, :antecedent_implications, :consequent_implications] end diff --git a/app/models/tag_relationship.rb b/app/models/tag_relationship.rb index 1ed46ad98..897894885 100644 --- a/app/models/tag_relationship.rb +++ b/app/models/tag_relationship.rb @@ -94,7 +94,7 @@ class TagRelationship < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :creator, :approver, :forum_topic_id, :forum_post_id, :antecedent_name, :consequent_name) + q = q.search_attributes(params, :antecedent_name, :consequent_name) if params[:name_matches].present? q = q.name_matches(params[:name_matches]) @@ -157,6 +157,14 @@ class TagRelationship < ApplicationRecord end end + def self.model_restriction(table) + 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 3d46380b7..e3e8cda1a 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -184,7 +184,7 @@ class Upload < ApplicationRecord def self.search(params) q = super - q = q.search_attributes(params, :uploader, :post, :source, :rating, :parent_id, :server, :md5, :server, :file_ext, :file_size, :image_width, :image_height, :referer_url) + q = q.search_attributes(params, :source, :rating, :parent_id, :server, :md5, :server, :file_ext, :file_size, :image_width, :image_height, :referer_url) if params[:source_matches].present? q = q.where_like(:source, params[:source_matches]) @@ -225,6 +225,10 @@ 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 89ab85e6e..a384cf325 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -513,7 +513,7 @@ class User < ApplicationRecord params = params.dup params[:name_matches] = params.delete(:name) if params[:name].present? - q = q.search_attributes(params, :name, :level, :inviter, :post_upload_count, :post_update_count, :note_update_count, :favorite_count) + q = q.search_attributes(params, :name, :level, :post_upload_count, :post_update_count, :note_update_count, :favorite_count) if params[:name_matches].present? q = q.where_ilike(:name, normalize_name(params[:name_matches])) @@ -582,6 +582,10 @@ 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_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 90690d56a..e7ffbcb45 100644 --- a/app/models/user_feedback.rb +++ b/app/models/user_feedback.rb @@ -32,7 +32,7 @@ class UserFeedback < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :user, :creator, :category, :body, :is_deleted) + q = q.search_attributes(params, :category, :body, :is_deleted) q = q.text_attribute_matches(:body, params[:body_matches]) q.apply_default_order(params) @@ -65,6 +65,10 @@ 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 73f7f8ced..1c7ea358b 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -48,10 +48,6 @@ class WikiPage < ApplicationRecord end end - def tag_matches(params) - where(title: Tag.search(params).select(:name).reorder(nil)) - end - def linked_to(title) where(dtext_links: DtextLink.wiki_page.wiki_link.where(link_target: normalize_title(title))) end @@ -78,10 +74,6 @@ class WikiPage < ApplicationRecord q = q.other_names_match(params[:other_names_match]) end - if params[:tag].present? - q = q.tag_matches(params[:tag]) - end - if params[:linked_to].present? q = q.linked_to(params[:linked_to]) end @@ -245,6 +237,14 @@ class WikiPage < ApplicationRecord end end + def self.model_restriction(table) + 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 4830b83fd..0b71a9501 100644 --- a/app/models/wiki_page_version.rb +++ b/app/models/wiki_page_version.rb @@ -9,7 +9,7 @@ class WikiPageVersion < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :updater, :is_locked, :is_deleted, :wiki_page_id) + q = q.search_attributes(params, :is_locked, :is_deleted) q = q.text_attribute_matches(:title, params[:title]) q = q.text_attribute_matches(:body, params[:body]) @@ -77,7 +77,11 @@ class WikiPageVersion < ApplicationRecord end end + def self.searchable_includes + [:updater, :wiki_page, :artist, :tag] + end + def self.available_includes - [:updater, :wiki_page, :artist] + [:updater, :wiki_page, :artist, :tag] end end