prelude icon indicating copy to clipboard operation
prelude copied to clipboard

Add strict form of each prelude method that forbids N+1s

Open brasic opened this issue 4 years ago • 1 comments

It's actually surprisingly possible in real world code to end up with an array mixed from several preloaded sources and some sources that are not preloaded at all, which can trigger N+1s on apparently preloaded data.

To make it possible to avoid this, add a strict form of each prelude method suffixed with ! which raises Prelude::StrictLoadingViolationError if it is called in a way that would otherwise lazily inject a Prelude::Preloader instance (and thus be a likely source of inadvertent N+1s).

brasic avatar Mar 16 '22 18:03 brasic

👋 Hey @brasic I was stopping by to write up https://github.com/seejohnrun/prelude/issues/15 on this repo and saw this. I noticed that https://github.com/seejohnrun/prelude/issues/15 is actually kind of the "inverse" case of the problem you describe here, where instead of lazily preloading for a single record, we can sometimes over preload when the intention was a single, lazy call. I don't think it changes anything about your suggestion here, but just thought you may find it interesting based on this PR!

WillHalto avatar Apr 05 '22 22:04 WillHalto