perf(relay): cache macro images instead of re-fetching every render

The relay web client re-fetched every macro image through the relay->desktop
proxy on each render (tab switch, WS update) and revoked the object URL on
load, so nothing was reused and fetches were serial — slow to display.

- Client: cache image_path -> Promise<objectURL> and reuse across renders
  (macro images are content-addressed by uuid, so immutable); fetch in
  parallel and de-duplicate concurrent requests.
- Proxy: send Cache-Control: private, max-age=31536000, immutable on image
  responses so the browser also disk-caches them across reloads.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-17 23:22:04 -07:00
parent 62559a59c9
commit 2bbbc5e283
2 changed files with 49 additions and 20 deletions
+4
View File
@@ -49,6 +49,10 @@ export function createApiProxy(
if (response.body?.base64 && response.body?.contentType) {
const buffer = Buffer.from(response.body.base64, 'base64');
res.set('Content-Type', response.body.contentType);
// Macro images are content-addressed (uuid filenames) and therefore
// immutable, so let the browser cache them aggressively. 'private'
// keeps them out of shared proxy caches since they sit behind auth.
res.set('Cache-Control', 'private, max-age=31536000, immutable');
res.send(buffer);
} else {
res.status(response.status).json(response.body);