Skip to content

Generating several N+1 queries when adding multiple resources to an export thus slowing down query and timing out Heroku #40

@subratrout

Description

@subratrout

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions