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:
evazion
2019-10-07 20:41:41 -05:00
parent e1f37113b3
commit 93dd952949
12 changed files with 131 additions and 182 deletions

View File

@@ -1,5 +1,4 @@
require 'test_helper'
require "danbooru/paginator/pagination_error"
module PostSets
class IntroTest < ActiveSupport::TestCase

View File

@@ -1,5 +1,4 @@
require 'test_helper'
require "danbooru/paginator/pagination_error"
module PostSets
class PostTest < ActiveSupport::TestCase
@@ -86,7 +85,7 @@ module PostSets
end
should "fail" do
assert_raises(Danbooru::Paginator::PaginationError) do
assert_raises(PaginationExtension::PaginationError) do
@set.posts
end
end