-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repeating Pagination Item #306
Comments
Hi @bradbajuz this looks like a AR count related quirk, due to the specific scope/query. Maybe related to one of the dreaded rails/rails#5554, rails/rails#1003, rails/rails#6865, ... not sure whether they have been fixed in your rails version... Can you investigate the actual queries used by pagy getting the count and AR getting the scope? FYI, you can get that in the console, you will see 2 AR querires firing each time you paginate: one is getting the count, and the other is getting the actual page of records. An easy way to do it in your console is using the Pagy::Console which is a very new addition, so you may have to update pagy to the latest version, if you use ruby 3+. The 2 queries are probably different, so the count returns a number, while the actual record count returned by that query is a different number. |
BTW, if that is the case, then you can avoid the problem by explicitly passing a |
I'm using Rails 6.1, Ruby 3.0.1, and Pagy 4.5.1 Even if I simplify my query by just using:
I still have the same issue. Output from the console:
|
You are not using any extra nor overriding, right? The queries look right. Could you also try the following: scope = User.all
scope_role = User.all.order(:role)
scope.count(:all)
scope_role.count(:all)
scope.offset(0).limit(10)
scope_role.offset(0).limit(10)
scope.offset(10).limit(10)
scope_role.offset(10).limit(10) |
Well, I've tried it in a similar environment with different number of items and pages, and it does not fail. Ever. However, I am using a sqlite DB in a pretty basic rails 6 app. Which DB are you using. Any other weird gem? Decorators or anything that may affect AR? |
How do you know that it is the same user record if they have possibly the same name? You should show the ID in the listing. Besides you didn't provide the output that I asked., which would show the actual records, not just the name. |
You're right. Sorry to make that look so vague. I've updated the previous post with new images and some more context. I'll provide a separate post with the outputs you asked. |
Thank you for the answer, and thanks for adding the ID in the listings.
So, since in the console we didn't use pagy at all and it displays the same problem that you are complaining about, how do you think that has anything to do with pagy? |
You're right it's not a Pagy issue. At the time it looked like it and I didn't know of any other way of troubleshooting it. Appreciate you helping me work through it. I'm assuming then this is an AR bug, right? I can go ahead an open an issue over on the Rails project and close this one. |
Before assuming (and posting an issue), you should be certain it is an issue. You are assuming it's AR now, similarly you was assuming it was pagy just a few hours ago. It could be any number of things or combination of things. If you suspect it is AR, then use only AR in isolation (maybe pure ruby, not even rails), no other gems that might change it without you knowing it, and check. Maybe without other gems you will not be able to reproduce it anymore.... or maybe the way you are using stuff in your own code change the outcome. An issue of a library should isolate the problem using only that library, or if not possible, the minimum number of other stuff around it, knowing/excluding that the other things around it are the actual problem. HTH |
For anyone stumbling across this issue and is using Postgresql, the problem is not with Pagy or Rails, it's just how PostgreSQL behaves with ORDERBY and LIMIT/OFFSET
https://www.postgresql.org/docs/16/queries-limit.html#:~:text=When%20using%20LIMIT,ORDER%20BY. |
@joyoy96 I fixed it |
I'm having a strange issue with a repeating item when sorting by user roles.
UserController:
User Model
On my user index page, I have a HTML table with a list of users that are being ordered by the User Role.
I'm paginating like so:
<%== pagy_bootstrap_nav(@pagy) %>
If a user with the role
unassigned
ends up at the bottom and there is more than one user that has a role ofunassigned
, the user will repeat again on the second page and one of the otherunassigned
users will be hidden.**This ONLY happens when I order by
:role
Example
I have three users that have the
unassigned
role: User1, User 14, and User 22.User 14 is on page one
![user-page-1](https://user-images.githubusercontent.com/2166808/116815745-e98a5580-ab2c-11eb-8f15-e6cca6fe17a4.jpg)
User 1 and User 14 (repeating) is on page two. User 22 is never displayed.
![user-page-2](https://user-images.githubusercontent.com/2166808/116815747-f1e29080-ab2c-11eb-96d1-76996b2bffab.jpg)
The text was updated successfully, but these errors were encountered: