hcb icon indicating copy to clipboard operation
hcb copied to clipboard

[Associations] Start adding `strict_loading`

Open garyhtou opened this issue 1 year ago • 4 comments

https://www.bigbinary.com/blog/rails-6-1-adds-strict_loading-to-warn-lazy-loading-associations

garyhtou avatar Jul 05 '24 19:07 garyhtou

Can this ticket be scoped out? Where do we want to use this?

sampoder avatar Dec 05 '24 07:12 sampoder

Strict loading is a Rails feature where when you call an association without preloading it, Rails will error to prevent an N+1. This forces us to fix/avoid N+1 issues and improve performance.

We'll start by gradually adding strict loading to commonly used associations on Event and User.

garyhtou avatar Dec 05 '24 22:12 garyhtou

link that @sampoder found: https://jordanhollinger.com/2023/11/11/rails-strict-loading/

garyhtou avatar Dec 05 '24 22:12 garyhtou

I think a good approach to this would be

  1. Setting config.active_record.action_on_strict_loading_violation = :log
  2. Working model-by-model to add self.strict_loading_by_default = true
  3. Temporarily setting config.active_record.action_on_strict_loading_violation = :raise
  4. Fixing all instances in that model
  5. Making a PR that fixes N+1 issues and adds strict loading by default to that model (to keep it in place going forward)

YodaLightsabr avatar Oct 14 '25 00:10 YodaLightsabr