Skip to content

[feature request] A less invasive "Suggestion" mode #153

@alfuken

Description

@alfuken

Sometimes, (rarely, but still), goldiloader preloads things that it shouldn't have.

Like, for example (actual code is not quite the same, though similar):

class Item < ApplicationRecord
  has_and_belongs_to_many :item_groups
end

class ItemGroup < ApplicationRecord
  has_and_belongs_to_many :items
end

class Bucket < ApplicationRecord
  belongs_to :item_group
  has_many :items, through: :item_group
end

There's millions of items, with thousands of groups and hundreds of buckets. When I'm calling @bucket.items.destroy_all, if at least one of the items belongs to any other group than the bucket's one - all hells break loose. Dozens of groups, tens, hundreds of thousands of items are being loaded from the database... And I've discovered this completely accidentally! Of course, one can disable automatic eager-loading on a case-by-case basis, but: how many more other similar places are in the code, when it loads things it shouldn't have?..

As I said, this setup is only a vague example — it might as well be some other associations or misconfigurations or shenanigans in the project, but, nevertheless — it would be nice to have an ability to run Goldiloader in a diagnostic/suggestions mode: instead of automagically autoloading things — print a message into the Rails log:

Goldiloader suggests eager-loading the `:item_group => :items` association for the Bucket class, called at `app/views/buckets/show.html.erb:18`

(with a config option to print the full backtrace, not just caller location)

That would be a most awesome addition. :)

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