railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.89k stars 2.26k forks source link

Preserve order when generating CSV #3575

Open pcai opened 1 year ago

pcai commented 1 year ago

Resolves #2580

Generate CSVs using kaminari pagination when available (e.g., when @objects is an ActiveRecord_Relation) instead of using the native rails find_each.

This allows us to preserve the activerecord ORDER BY clause defined when browsing records before attempting to export them; find_each overrides the ORDER BY to use the primary key id.

One potential downside to this is that it will make certain large exports much less efficient, as paginating large tables ordered by a column without the correct database indexes will run into algorithmic problems.

Issue reproduction:

EXPECTED:

ACTUAL:

coveralls commented 1 year ago

Coverage Status

coverage: 96.044% (+0.08%) from 95.965% when pulling d90183fd080df945bcd7212c8b80014b443b018b on pcai:order-csv-exports into e158beb6a42ee74c7f90807186f5b141e7b20547 on railsadminteam:master.

pcai commented 4 months ago

I'm still looking for feedback on this. I don't mind keeping it up to date and passing CI, but I would appreciate some guidance on whether the change would be accepted at all.