Commit bc559ca
Serve ActiveStorage attachments via the proxy endpoint (#9422)
Partner/advert logos are rendered with `image_tag advert.light_logo`, which
resolves to ActiveStorage's blob *redirect* endpoint. That endpoint 302s to a
presigned S3 URL, and Rails serves the redirect as `Cache-Control: max-age=...,
private` (`expires_in ActiveStorage.service_urls_expire_in`, no `public: true`),
capped at the signature's lifetime. Cloudflare never caches a `private`
response, so the two advert logos were hitting origin ~7k times each per 12h.
Switching `resolve_model_to_route` to `:rails_storage_proxy` gives a permanent
URL served by `ActiveStorage::Blobs::ProxyController`, which sets
`public, max-age=<forever>` and disables the session, so there's no `Set-Cookie`
to bypass the edge either. Cloudflare fetches each blob once per PoP.
Claude-Session: https://claude.ai/code/session_01JLa7RVZtKEECSsYczu458W
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent a419531 commit bc559ca
2 files changed
Lines changed: 45 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
40 | 48 | | |
41 | 49 | | |
42 | 50 | | |
| |||
| 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 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
0 commit comments