Support activerecord associations preloader#391
Support activerecord associations preloader#391OuYangJinTing wants to merge 1 commit intoruby-grape:masterfrom
Conversation
- Add new `:preload` exposure option - Add `Grape::Entity.preload_and_represent` helper method - Add `Grape::Entity::Preloader` class for preload activerecord associations
|
Hi @OuYangJinTing, Many thanks for diving deep into this! I really appreciate how thoroughly you addressed the N+1 query problem - great test coverage, elegant That said, I wonder if introducing ActiveRecord-specific logic into grape-entity core might blur its intended boundaries.
Overall, it's a well-intentioned and technically solid proposal, but I think it could move the core gem away from its primary simplicity and flexibility. One idea that might strike a good balance: extract this functionality into a separate adapter gem, e.g.
That way, users needing AR-specific behavior can opt in cleanly - while the core remains lean and focused. Let's hear what the other maintainers think as well - getting more perspectives sounds like the right next step. Again, thank you for the hard thinking, craftsmanship, and initiative here. I’m really glad to have contributors willing to tackle real pain-points like N+1, and I’m looking forward to figuring out together what the best, most maintainable path forward could be. |
|
@numbata Sorry, I replied late due to some delays. Thank you very much for your detailed reply, explanation and suggestions. |
This PR introduces ActiveRecord associations preloading to reduce N+1 queries when serializing nested exposures.
Key points:
Why:
Please see the branch for details. Feedback welcome.