railsadminteam / rails_admin

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

Please bring back optional horizontal pagination #3680

Closed elleaiello closed 1 month ago

elleaiello commented 2 months ago

Hi there 👋

I recently upgraded our Rails 6.1 project from v2 to v3 of Rails Admin. We are seeing performance hit as a result of the now default sidescrolling when viewing the list of records for certain models. This was not a problem previously because of the horizontal pagination. However, we are now running into memory issues because ALL the associations on the first few records are fetched from the db and loaded into memory to display in the table.

Feature request: please could you bring back the sidescroll option or similar config. I'm happy to create a PR for this if you'd like? There isn't much context in the removal commit (https://github.com/railsadminteam/rails_admin/commit/d51e94314de4b510df0767a695d5953bb7b3fad5) as to why it was removed, so wanted to check first.

I can solve my issue by restricting the fields on the terribly performing models (I am excluding most of the has_many associations), but a universal solution would be better... Sidescrolling worked well enough to solve this! An alternative would be an option not to load associations 🤔

Also let me know if there's some solution/workaround I'm missing 🤠

mshibuya commented 2 months ago

The optional sidescroll feature was removed because it adds maintenance overhead. Making it the default behavior allowed removal of conditionals and logics from the codebase, as you can see from the commit.

we are now running into memory issues because ALL the associations on the first few records are fetched from the db and loaded into memory to display in the table.

That happens, especially with has_many associations as you mentioned. My recommendation is to always use the field directive to explicitly opt-in the fields to be shown. This usually results in better usability unless the model is very simple (in your case that's not the case), as you can show only fields that are meaningful to users with friendly order.

You can also exclude all has_many fields like this, though I don't recommend much.

  config.model Foo do
    fields_of_type :has_many_association do
      hide
    end
  end
elleaiello commented 2 months ago

Thanks @mshibuya, I think the blanket exclusion of has_many fields is what I'm looking for. Why don't you recommend it?

mshibuya commented 2 months ago

As I wrote, being explicit is the better and more flexible way.