-
Alex Ghiculescu authored
https://github.com/rails/rails/pull/31250 optimised rendering a collection with `cached: true`, but also with `cached: proc {}`. The problem is the proc may reference associations that should be preloaded to avoid n+1s in generating the cache key. For example: ```ruby @posts = Post.preload(:author) @view.render partial: "test/partial", collection: @post, cached: proc { |post| [post, post.author] } ``` This will n+1 on `post.author`. To fix this, this PR will always preload the collection if there's a proc given for `cached`. `cached: true` will still not preload unless it renders, as it did in https://github.com/rails/rails/pull/31250.
Alex Ghiculescu authoredhttps://github.com/rails/rails/pull/31250 optimised rendering a collection with `cached: true`, but also with `cached: proc {}`. The problem is the proc may reference associations that should be preloaded to avoid n+1s in generating the cache key. For example: ```ruby @posts = Post.preload(:author) @view.render partial: "test/partial", collection: @post, cached: proc { |post| [post, post.author] } ``` This will n+1 on `post.author`. To fix this, this PR will always preload the collection if there's a proc given for `cached`. `cached: true` will still not preload unless it renders, as it did in https://github.com/rails/rails/pull/31250.
Loading