valkyrie icon indicating copy to clipboard operation
valkyrie copied to clipboard

Strategy for N+1 Queries

Open tpendragon opened this issue 7 years ago • 1 comments

This finally showed up in Figgy!

We have two cases in production of the app running N+1 queries and causing measurable performance degradation - https://github.com/pulibrary/figgy/issues/1658 and https://github.com/pulibrary/figgy/issues/1656. What do we need to add in Valkyrie to deal with this?

My current thought is to provide another meta tag on attributes like attribute :loaded_queries, Valkyrie::Types::Set.optional.meta(virtual: true), where the virtual: true setting prevents the attribute from being persisted. That way custom queries could populate that value with whatever, allowing for custom queries like find_members_with_thumbnails.

tpendragon avatar Aug 14 '18 17:08 tpendragon

We have a strategy we're prototyping in Figgy now that's working so far - we just added an attr_accessor :loaded to our resources and a custom query populates that hash with preloaded resources, then our decorators check to see if it's populated and only runs a query if it's empty.

tpendragon avatar Sep 28 '18 22:09 tpendragon