Strategy for N+1 Queries
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.
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.