-
Notifications
You must be signed in to change notification settings - Fork 52
Description
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. :)