statamic-rad-pack / runway

Eloquently manage your database models in Statamic.
https://statamic.com/runway
MIT License
107 stars 43 forks source link

[6.x] Fix N+1 queries in ResourceActionController #470

Closed caseydwyer closed 2 months ago

caseydwyer commented 2 months ago

Closes #469. After this change, models are essentially eager-loaded, using the findMany method inside getSelectedItems. See #469 for a before, and here's an after (see query counter in the debugbar):

n-plus-1-after

This also has (what I would consider) an added benefit, by returning an eloquent collection, instead of a generic collection. Allows you to do some handy things within the Action class itself, like $items->load('anotherRelation'). Wanted to mention this in case it impacts anything downstream that I'm unaware of, but should just be a net-positive since the eloquent collection class extends the base collection class. 👍

Let me know if we need to tweak anything, here!

duncanmcclean commented 2 months ago

Thanks for this! I'll review it when I can.

github-actions[bot] commented 2 months ago

Released as part of v6.6.3.