ActiveAdmin automatically loads the complete connection table

I am working on a project that uses ActiveAdmin for its administration.

I have two models, a book model in which there are products. When I try to access the product index view in ActiveAdmin, it seems that it is trying to load the entire table of books into memory (there are about 1.5 million books in my database). CPU usage reaches 100%, and memory usage up to gigabytes.

Enabling mysql logging confirms that this happens when this view is called:

17 Query SELECT `books`.* FROM `books` 

As far as I can tell this, this happens before any attempt to download products.

To understand this problem, I stripped the models to their bare bones:

 class Product < ActiveRecord::Base belongs_to :book end class Book < ActiveRecord::Base has_many :products end 

I also reduced the definition of AA to its basic form:

 ActiveAdmin.register Product do end 

Is this normal for ActiveAdmin? This does not seem to be the desired behavior.

+6
source share
1 answer

For those who are dealing with the same problem, I finally traced it to the automatically created sidebar in ActiveAdmin. This includes a search field that includes a selection field for all related records.

If you have a linked table with more than a million records, for example, I am doing AA, we will gladly try to insert the entire table in the selection box.

The answer was to include some custom filters in the AA definition for such products:

 ActiveAdmin.register Product do filter :title end 

Thus, the association will not be included (unless you specify it yourself).

+26
source

Source: https://habr.com/ru/post/952897/


All Articles