Skip to content
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

API controller indexes are ordered backwards. #408

Closed
andrewculver opened this issue Aug 16, 2023 · 3 comments · Fixed by #494
Closed

API controller indexes are ordered backwards. #408

andrewculver opened this issue Aug 16, 2023 · 3 comments · Fixed by #494
Assignees

Comments

@andrewculver
Copy link
Contributor

andrewculver commented Aug 16, 2023

Given the way we use cursor pagination and an after attribute with the ID of the last result, I would have expected IDs to be ascending order, but they're not. As a result of this, pagination is effectively broken, at least on MySQL?

I fixed this downstream by overriding apply_pagination like so. The important part here is the order: {id: :asc}.

  def apply_pagination
     collection = instance_variable_get collection_variable
     # The `pagy_cursor` gem appears to default to `order: {id: :desc}`?
     @pagy, collection = pagy_cursor collection, after: params[:after], order: {id: :asc}
     instance_variable_set collection_variable, collection
   end
@andrewculver andrewculver changed the title API controller indexes are ordered backwards. API controller indexes are ordered backwards, breaking cursor pagination. Aug 16, 2023
@andrewculver andrewculver changed the title API controller indexes are ordered backwards, breaking cursor pagination. API controller indexes are ordered backwards. Aug 16, 2023
@gazayas
Copy link
Contributor

gazayas commented Aug 16, 2023

Very strange... I noticed it happening recently on my machine, and I reverted back to 1.25.0 for all of our BT gems but I still get the same test failure there so I'm not sure where it was introduced 🤔 Using PostgreSQL.

@gazayas
Copy link
Contributor

gazayas commented Aug 16, 2023

I'm seeing that the following bit (that our pagination test uses) returns tangible things in descending order

<%= render 'account/scaffolding/completely_concrete/tangible_things/index', tangible_things: @creative_concept.completely_concrete_tangible_things, hide_back: true %>

Tagging the oldest scope onto the end returns them in the proper order, but it seems like this is happening before we even hit pagy in the index partial. Will continue digging.

@jagthedrummer
Copy link
Contributor

I went ahead and merged #409 so that we can get a fix in place, but I'm leaving this issue open so that we can look for a better fix to the root cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants