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:
Navigate to a records index page and change the sort ordering (e.g., sort by "Name descending"):
Click "export found _____"
generate the CSV
EXPECTED:
the generated CSV has the sort ordering from the previous step
coverage: 96.044% (+0.08%) from 95.965% when pulling d90183fd080df945bcd7212c8b80014b443b018b on pcai:order-csv-exports into e158beb6a42ee74c7f90807186f5b141e7b20547 on railsadminteam:master.
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.
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: