When I am trying to export a resource which has two or three other related models data to be exported along with it, it is generating several N+1 queries and with couple of thousand rows I am facing server time out issues.
Upon installing bullet gem I get following on my bullet.log
USE eager loading detected
Resource => [:sponsorships]
Add to your query: .includes([:sponsorships])
GET /admin/resources/export.csv
USE eager loading detected
Resource => [:organizations]
Add to your query: .includes([:organizations])
Just for example my resource_dashboard contains following:
```ATTRIBUTE_TYPES = {
id: Field::Number,
name: Field::String,
resource_type: Field::Enumerate,
organizations: Field::HasMany.with_options(
transform_on_export: -> (field) { field.data&.map(&:name)&.join(", ") if field.data }
),
event_detail: Field::HasOne,
questions: Field::NestedHasMany.with_options(
skip: :resource,
transform_on_export: -> (field) { field.data&.map(&:text)&.join(", ") if field.data }
),
Is there a way to speed up query or prevent eager loading?