简体   繁体   English

如何优化active_admin

[英]How can I optimize active_admin

Last time I got the problem with active_admin . 上次我遇到active_admin的问题。 In tables where I have 5000+ rows of data it's work very slowly. 在我有5000多行数据的表格中,它的工作速度非常慢。 How I can optimize it? 我该如何优化呢? Maybe somebody know some async load plugins for this module? 也许有人知道这个模块的一些异步加载插件?

There are a couple things you can do. 你可以做几件事。

By default, Active Admin loads associations as drop-down filters on the index page. 默认情况下,Active Admin将关联作为下拉过滤器加载到索引页面上。 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. 这实际上并不适用,因为您只有5000条记录,但是如果您达到甚至表的DB COUNT需要很长时间的程度,您可能希望禁用索引页右下角的计数。 (this feature was added in 0.6.1) (此功能已在0.6.1中添加)

ActiveAdmin.register Post do
  index pagination_total: false
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM