eBooru/app/logical/post_search_context.rb
Earlopain fc7d84affd
[RuboCop] Enable Style/FrozenStringLiteralComment
This reduces allocations on the posts page by about 5%, from basic testing
2024-02-25 18:15:55 +01:00

14 lines
488 B
Ruby

# frozen_string_literal: true
class PostSearchContext
attr_reader :post
def initialize(params)
tags = params[:q].presence || params[:tags].presence || ""
tags += " rating:s" if CurrentUser.safe_mode?
tags += " -status:deleted" unless TagQuery.has_metatag?(tags, "status", "-status")
pagination_mode = params[:seq] == "prev" ? "a" : "b"
@post = Post.tag_match(tags).paginate("#{pagination_mode}#{params[:id]}", limit: 1).first || Post.find(params[:id])
end
end