Make PostQueryBuilder apply aliases earlier, immediately after parsing the search. On the post index page there are multiple places where we need to apply aliases: * When running the search with PostQueryBuilder#build. * When calculating the search count with PostQueryBuilder#fast_count. * When calculating the related tags for the sidebar. * When tracking missed searches and popular searches for Reportbooru. * When looking up wiki excerpts. Applying aliases after parsing ensures we only have to apply aliases once for all of these things. We also normalize the order of tags in searches and strip repeated tags. This is so that we have consistent cache keys for fast_count. * Fixes searches for aliased tags being counted as missed searches (fixes #4433). * Fixes wiki excerpts not showing up when searching for aliased tags.
65 lines
2.0 KiB
Ruby
65 lines
2.0 KiB
Ruby
module PostsHelper
|
|
def post_previews_html(posts, **options)
|
|
posts.map do |post|
|
|
PostPresenter.preview(post, **options)
|
|
end.join("").html_safe
|
|
end
|
|
|
|
def post_search_counts_enabled?
|
|
Danbooru.config.enable_post_search_counts && Danbooru.config.reportbooru_server.present? && Danbooru.config.reportbooru_key.present?
|
|
end
|
|
|
|
def discover_mode?
|
|
params[:tags] =~ /order:rank/ || params[:action] =~ /searches|viewed/
|
|
end
|
|
|
|
def missed_post_search_count_js(tags)
|
|
sig = generate_reportbooru_signature(tags)
|
|
render "posts/partials/index/missed_search_count", sig: sig
|
|
end
|
|
|
|
def post_search_count_js(tags)
|
|
sig = generate_reportbooru_signature("ps-#{tags}")
|
|
render "posts/partials/index/search_count", sig: sig
|
|
end
|
|
|
|
def post_view_count_js
|
|
return unless post_search_counts_enabled?
|
|
|
|
msg = generate_reportbooru_signature(params[:id])
|
|
render "posts/partials/show/view_count", msg: msg
|
|
end
|
|
|
|
def generate_reportbooru_signature(value)
|
|
verifier = ActiveSupport::MessageVerifier.new(Danbooru.config.reportbooru_key, serializer: JSON, digest: "SHA256")
|
|
verifier.generate("#{value},#{session[:session_id]}")
|
|
end
|
|
|
|
def post_source_tag(source, normalized_source = source)
|
|
# Only allow http:// and https:// links. Disallow javascript: links.
|
|
if source =~ %r!\Ahttps?://!i
|
|
external_link_to(normalized_source, strip: :subdomain) + " ".html_safe + link_to("»", source, rel: "external noreferrer nofollow")
|
|
else
|
|
source
|
|
end
|
|
end
|
|
|
|
def post_favlist(post)
|
|
post.favorited_users.reverse_each.map {|user| link_to_user(user)}.join(", ").html_safe
|
|
end
|
|
|
|
def is_pool_selected?(pool)
|
|
return false if params.key?(:q)
|
|
return false if params.key?(:favgroup_id)
|
|
return false if !params.key?(:pool_id)
|
|
return params[:pool_id].to_i == pool.id
|
|
end
|
|
|
|
private
|
|
|
|
def nav_params_for(page)
|
|
query_params = params.except(:controller, :action, :id).merge(page: page).permit!
|
|
{ params: query_params }
|
|
end
|
|
end
|