Search code examples
ruby-on-railsrubyruby-on-rails-3activeadmin

How can I optimize active_admin


When I use active_admin with tables that have 5000+ records in them everything becomes very slow. How I can optimise it? Does anybody know some plugins which would allow me to load the data asynchronously?


Solution

  • There are a couple things you can do.

    By default, Active Admin loads associations as drop-down filters on the index page. If those filters aren't being used, it helps to remove them because they instantiate every record of that model to build the drop-down.

    ActiveAdmin.register Post do
      remove_filter :categories
    end
    

    If your index page has columns that depend on associated records, it helps to eager-load them.

    ActiveAdmin.register Post do
      controller do
        def scoped_collection
          super.includes :author, :publisher
        end
      end
    end
    

    This doesn't really apply since you only have 5000 records, but if you get to the point where even a DB COUNT of the table takes a long time, you might want to disable the count in the bottom right of the index page. (this feature was added in 0.6.1)

    ActiveAdmin.register Post do
      index pagination_total: false
    end