pagination: refactor to avoid counting pages in API.
Previously the page-based (numbered) paginator would always count the total_pages, even in API calls when it wasn't needed. This could be very slow in some cases. Refactor so that total_pages isn't calculated unless it's called. While we're at it, refactor to condense all the sequential vs. numbered pagination logic into one module. This incidentally fixes a couple more bugs: * "page=b0" returned all pages rather than nothing. * Bad parameters like "page=blaha123" and "page=a123blah" were accepted.
This commit is contained in:
@@ -62,7 +62,7 @@ class ApplicationController < ActionController::Base
|
||||
render_error_page(405, exception)
|
||||
when ActionController::UnknownFormat, ActionView::MissingTemplate
|
||||
render_error_page(406, exception, message: "#{request.format.to_s} is not a supported format for this page")
|
||||
when Danbooru::Paginator::PaginationError
|
||||
when PaginationExtension::PaginationError
|
||||
render_error_page(410, exception, template: "static/pagination_error", message: "You cannot go beyond page #{Danbooru.config.max_numbered_pages}.")
|
||||
when Post::SearchError
|
||||
render_error_page(422, exception, template: "static/tag_limit_error", message: "You cannot search for more than #{CurrentUser.tag_query_limit} tags at a time.")
|
||||
|
||||
Reference in New Issue
Block a user