pools: add ability to search for pools linking to given tag.
Add ability to search for pools linking to a given tag in the pool
description. Example:
https://danbooru.donmai.us/pools?search[linked_to]=touhou
(This isn't actually exposed in the UI to avoid cluttering the pool
search form with rarely used options.)
Pools with broken links can be found here:
https://danbooru.donmai.us/dtext_links?search[has_linked_tag]=No&search[has_linked_wiki]=No&search[model_type]=Pool
Lays the groundwork for fixing #4629.
This commit is contained in:
@@ -5,7 +5,6 @@ class WikiPage < ApplicationRecord
|
||||
|
||||
META_WIKIS = ["list_of_", "tag_group:", "pool_group:", "howto:", "about:", "help:", "template:"]
|
||||
|
||||
before_save :update_dtext_links, if: :dtext_links_changed?
|
||||
after_save :create_version
|
||||
|
||||
normalize :title, :normalize_title
|
||||
@@ -22,9 +21,9 @@ class WikiPage < ApplicationRecord
|
||||
has_one :tag, :foreign_key => "name", :primary_key => "title"
|
||||
has_one :artist, -> { active }, foreign_key: "name", primary_key: "title"
|
||||
has_many :versions, -> {order("wiki_page_versions.id ASC")}, :class_name => "WikiPageVersion", :dependent => :destroy
|
||||
has_many :dtext_links, as: :model, dependent: :destroy
|
||||
|
||||
deletable
|
||||
has_dtext_links :body
|
||||
|
||||
module SearchMethods
|
||||
def find_by_id_or_title(id)
|
||||
@@ -58,14 +57,6 @@ class WikiPage < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def linked_to(title)
|
||||
where(dtext_links: DtextLink.wiki_page.wiki_link.where(link_target: normalize_title(title)))
|
||||
end
|
||||
|
||||
def not_linked_to(title)
|
||||
where.not(dtext_links: DtextLink.wiki_page.wiki_link.where(link_target: normalize_title(title)))
|
||||
end
|
||||
|
||||
def default_order
|
||||
order(updated_at: :desc)
|
||||
end
|
||||
@@ -213,14 +204,6 @@ class WikiPage < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def dtext_links_changed?
|
||||
body_changed? && DText.dtext_links_differ?(body, body_was)
|
||||
end
|
||||
|
||||
def update_dtext_links
|
||||
self.dtext_links = DtextLink.new_from_dtext(body)
|
||||
end
|
||||
|
||||
def tags
|
||||
titles = DText.parse_wiki_titles(body).uniq
|
||||
tags = Tag.nonempty.where(name: titles).pluck(:name)
|
||||
|
||||
Reference in New Issue
Block a user