Skip to content

Commit

Permalink
Retrieve only @in items:
Browse files Browse the repository at this point in the history
- improve the performance of the last page in
particular storage conditions (see #696)
  • Loading branch information
ddnexus committed May 5, 2024
1 parent 8fc1b1e commit 9a0bffa
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gem/lib/pagy/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def pagy_get_page(vars)
# Sub-method called only by #pagy: here for easy customization of record-extraction by overriding
# You may need to override this method for collections without offset|limit
def pagy_get_items(collection, pagy)
collection.offset(pagy.offset).limit(pagy.items)
collection.offset(pagy.offset).limit(pagy.in)
end
end
end
2 changes: 1 addition & 1 deletion gem/lib/pagy/extras/overflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(vars)
initialize vars.merge!(page: @last) # re-run with the last page
@vars[:page] = requested_page # restore the requested page
when :empty_page
@offset = @items = @from = @to = 0 # vars relative to the actual page
@offset = @items = @in = @from = @to = 0 # vars relative to the actual page
if defined?(Calendar) && is_a?(Calendar) # only for Calendar instances
edge = @order == :asc ? @final : @initial # get the edge of the overflow side (neat, but any time would do)
@from = @to = edge # set both to the edge utc time (a >=&&< query will get no records)
Expand Down
2 changes: 1 addition & 1 deletion test/pagy/extras/overflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
_(pagy.page).must_equal 100
_(pagy.offset).must_equal 0
_(pagy.items).must_equal 0
_(pagy.in).must_be_nil
_(pagy.in).must_equal 0
_(pagy.from).must_equal 0
_(pagy.to).must_equal 0
_(pagy.prev).must_equal pagy.last
Expand Down

0 comments on commit 9a0bffa

Please sign in to comment.