Convert models to use new search includes mechanism
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user