Skip to content

Commit

Permalink
Fix pagy.in in pagy_get_items method introduced in 8.4.0 (see #696) (c…
Browse files Browse the repository at this point in the history
…loses #704) (closes #708) (#707)
  • Loading branch information
benkoshy committed Jun 2, 2024
1 parent 9ebb2ef commit 8206aa6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,18 @@ In the specific `bootstrap` example you could override the default bootstrap `"p

!!!

==- Slow Last Page

There has been a single report of a slow last page using very big DB tables. It's a pure DB problem and it's not caused by
pagy or by any other ruby code ([#696](https://github.com/ddnexus/pagy/pull/696),
[#704](https://github.com/ddnexus/pagy/pull/704)), but a simple pagy override may avoid it:

```rb
## override pagy_get_items
def pagy_get_items(collection, pagy)
limit = pagy.last == pagy.page ? pagy.in : pagy.items
collection.offset(pagy.offset).limit(limit)
end
```
!!!
===
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.in)
collection.offset(pagy.offset).limit(pagy.items)
end
end
end

0 comments on commit 8206aa6

Please sign in to comment.