Commit 78572dc
Memoize Site.instance per-request via RequestStore
Site.instance (upstream Hyku) uses first_or_create with no
memoization -- every call is a fresh DB round-trip. Profiling found a
single /catalog page load calls it ~650-680 times, almost entirely
through the `delegate :account, ..., to: :instance` line (the
ubiquitous Site.account accessor), not through one obvious N+1 loop.
Memoizes via RequestStore (already a transitive dependency), matching
how current_account is already memoized in ApplicationController and
HykuHelper. RequestStore clears automatically at each request
boundary, lining up with when Apartment re-resolves the tenant -- no
risk of a stale Site leaking across tenants on a reused Puma thread.
Verified locally (docker compose): confirmed genuine red (2 of 4
examples fail) with this file removed, and green with it restored.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent 4a35aa3 commit 78572dc
1 file changed
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
0 commit comments