Closed ryanmccarthypdx closed 4 months ago
We recently undid that exact thing as it causes performance issues. This is because there is no way to ensure that pre_render
is called only once. During rendering, every time Blueprinter hits an association, it makes a "render" call, which then calls pre_render
. This causes things that had already been pre-loaded at a higher level to be preloaded again.
As things currently stand in Blueprinter's codebase, there's no way to distinguish between that original pre_render
call and the nested ones.
I think the issue is that we are using the CollectionProxy as a shorthand for 'nested relation, and therefore already loaded'. But there are more direct ways of getting that information.
See PR here: https://github.com/procore-oss/blueprinter-activerecord/pull/28
Fixed in 1.2.0.
Consider the following:
Basically, I want to change the check in the Preloader#pre_render from matching on class name to
is_a?(ActiveRecord::Relation)
to include all relevant child classes.