-
- Downloads
Cache Routable#full_path in RequestStore to reduce duplicate route loads
We see in #27387 that a call to `polymorphic_path` will cause duplicate SELECT route calls for each merge request in a milestone. This happens because calling `project.namespace.becomes(Namespace)` will instantiate a new instance of a Namespace for each merge request, which causes a N+1 query on the routes table. This change caches the state of the route by the specific class and ID, which dramatically eliminates duplicate work.
Showing
- app/models/concerns/routable.rb 13 additions, 2 deletionsapp/models/concerns/routable.rb
- changelogs/unreleased/sh-optimize-duplicate-routable-full-path.yml 4 additions, 0 deletions...s/unreleased/sh-optimize-duplicate-routable-full-path.yml
- spec/models/concerns/routable_spec.rb 18 additions, 0 deletionsspec/models/concerns/routable_spec.rb
Please register or sign in to comment