diff --git a/app/logical/post_query.rb b/app/logical/post_query.rb
index 706492dd0..80bcc73b3 100644
--- a/app/logical/post_query.rb
+++ b/app/logical/post_query.rb
@@ -38,7 +38,9 @@ class PostQuery
# Perform a search and return the resulting posts
def self.search(search, ...)
- PostQuery.normalize(search, ...).with_implicit_metatags.posts
+ post_query = PostQuery.normalize(search, ...)
+ post_query.validate_tag_limit!
+ post_query.with_implicit_metatags.posts
end
def initialize(search_or_ast, current_user: User.anonymous, tag_limit: nil, safe_mode: false)
@@ -71,12 +73,12 @@ class PostQuery
end
def posts
- validate!
+ validate_metatags!
builder.posts(to_cnf)
end
def paginated_posts(...)
- validate!
+ validate_metatags!
builder.paginated_posts(to_cnf, ...)
end
@@ -189,9 +191,10 @@ class PostQuery
# Implicit metatags are metatags added by the user's account settings. rating:s is implicit under safe mode.
def implicit_metatags
- metatags = []
- metatags << AST.metatag("rating", "s") if safe_mode?
- metatags
+ return [] unless safe_mode?
+
+ tags = Danbooru.config.safe_mode_restricted_tags.map { |tag| -AST.tag(tag) }
+ [AST.metatag("rating", "s"), *tags]
end
# XXX unify with PostSets::Post#show_deleted?
@@ -272,18 +275,13 @@ class PostQuery
end
concerning :ValidationMethods do
- def validate!
- return if is_empty_search? || is_simple_tag?
-
- validate_tag_limit!
- validate_metatags!
- end
-
def validate_tag_limit!
+ return if is_empty_search? || is_simple_tag?
raise TagLimitError if tag_limit.present? && term_count > tag_limit
end
def validate_metatags!
+ return if is_empty_search? || is_simple_tag?
return if metatags.empty?
order_metatags = select_metatags(*ORDER_METATAGS)
diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb
index e31da76aa..607ebf4be 100644
--- a/app/logical/post_sets/post.rb
+++ b/app/logical/post_sets/post.rb
@@ -36,7 +36,7 @@ module PostSets
# The description of the page for the tag.
def meta_description
# XXX post_count may be nil if the search times out because of safe mode
- if normalized_query.is_simple_tag? && post_count.present?
+ if post_query.is_simple_tag? && post_count.present?
humanized_count = ApplicationController.helpers.humanized_number(post_count, million: " million", thousand: " thousand")
humanized_count = "over #{humanized_count}" if post_count >= 1_000
@@ -106,7 +106,8 @@ module PostSets
end
def posts
- @posts ||= normalized_query.paginated_posts(page, includes: includes, count: post_count, search_count: !post_count.nil?, limit: per_page, max_limit: max_per_page).load
+ post_query.validate_tag_limit!
+ normalized_query.paginated_posts(page, includes: includes, count: post_count, search_count: !post_count.nil?, limit: per_page, max_limit: max_per_page).load
end
# @return [Integer, nil] The number of posts returned by the search, or nil if unknown.
@@ -197,6 +198,6 @@ module PostSets
end
end
- memoize :page_title
+ memoize :page_title, :posts
end
end
diff --git a/app/models/post.rb b/app/models/post.rb
index 961ce938c..2ea366e10 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -1336,6 +1336,7 @@ class Post < ApplicationRecord
# @return [ActiveRecord::Relation] the set of resulting posts
def user_tag_match(query, user = CurrentUser.user, tag_limit: user.tag_query_limit, safe_mode: CurrentUser.safe_mode?)
post_query = PostQuery.normalize(query, current_user: user, tag_limit: tag_limit, safe_mode: safe_mode)
+ post_query.validate_tag_limit!
post_query.with_implicit_metatags.posts
end
diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb
index 9d73107c8..68001fab0 100644
--- a/config/danbooru_default_config.rb
+++ b/config/danbooru_default_config.rb
@@ -253,7 +253,7 @@ module Danbooru
# Tags that are not visible in safe mode.
def safe_mode_restricted_tags
- restricted_tags + %w[censored condom nipples nude penis pussy sexually_suggestive]
+ []
end
# If present, the 404 page will show a random post from this pool.