Stop album art from blocking page loads
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 13s
CI / federation-interop (push) Successful in 1m39s
CI / test (push) Successful in 3m38s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / trigger-deploy (push) Skipped
CI / notify (push) Successful in 5s
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 13s
CI / federation-interop (push) Successful in 1m39s
CI / test (push) Successful in 3m38s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / trigger-deploy (push) Skipped
CI / notify (push) Successful in 5s
Root cause: gunicorn runs only 2 sync workers, and GET /api/v1/art/album did its MusicBrainz + Cover Art Archive work synchronously inside the request (2-12+ seconds per call, measured). A page with several uncached albums could tie up the entire application - every endpoint, every user - for as long as that took. Separately, even an already-resolved album re-streamed its image bytes live from Cover Art Archive on every single page view, by the original v1 design. The endpoint is now cache-only: it reads the album_art table and, if resolved, a local file, and never touches the network. A cache miss records a "pending" row and returns 404 immediately - the frontend already treats 404 as "show the placeholder," so no frontend changes are needed. A new background worker task (the same claim-with- FOR-UPDATE-SKIP-LOCKED pattern already used by imports and federation deliveries) does the actual resolving and downloads the image bytes to a shared volume, completely decoupled from any request. No migration needed: AlbumArt.status just gains a new "pending" value. Verified against the real docker compose stack (not just the test suite): cold lookups for 5 real albums all returned 404 in well under 0.2s (previously 2-12+s each), the worker resolved all 5 within ~10s in the background, and resolved art then served in single-digit milliseconds from the volume, including after a full container restart (no re-download). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Hn2QwS1HRT8tFAzo8ew63
This commit is contained in:
1 parent
79193fbc8e
commit
83b27d7ba1
11 files changed
+345
-68
No files matched your search
+12
-3
@@ -16,8 +16,12 @@ Prometheus ◄── API :9100/metrics, postgres-exporter ──► Grafana
|
||||
|
||||
- **`api`**: Flask under gunicorn. API-only; it serves no HTML pages.
|
||||
- **`ui`**: nginx serving the static frontend (`frontend/`, no build step).
|
||||
- **`worker`**: `flask worker` — history imports and background tasks for optional
|
||||
modules (federation's deliveries, scheduled posts, and so on).
|
||||
- **`worker`**: `flask worker` — history imports, resolving and downloading album art
|
||||
(MusicBrainz + Cover Art Archive), and background tasks for optional modules
|
||||
(federation's deliveries, scheduled posts, and so on). This is the only service that
|
||||
makes outbound calls to third-party APIs (Last.fm, MusicBrainz, Cover Art Archive, and
|
||||
remote fediverse servers with federation on) — worth knowing if you're restricting
|
||||
egress.
|
||||
- **`db`**: PostgreSQL.
|
||||
- With the `monitoring` profile: `prometheus`, `grafana`, `postgres-exporter`.
|
||||
|
||||
@@ -54,7 +58,8 @@ read **Putting it behind TLS** below — the quick start above serves plain HTTP
|
||||
| `WEB_CONCURRENCY` | api | `2` | gunicorn workers |
|
||||
| `RUN_MIGRATIONS` | api image | `1` | Apply database migrations on start |
|
||||
| `LASTFM_API_KEY` | api, worker | *(unset)* | Enables importing straight from Last.fm ([get a key](https://www.last.fm/api/account/create)) |
|
||||
| `MUSICBRAINZ_CONTACT` | api | `UI_BASE_URL` | Contact URL/email sent to MusicBrainz for album art lookups (no key needed, but they ask for one) |
|
||||
| `MUSICBRAINZ_CONTACT` | api, worker | `UI_BASE_URL` | Contact URL/email sent to MusicBrainz for album art lookups (no key needed, but they ask for one) |
|
||||
| `ART_STORAGE_DIR` | api, worker | `var/album-art` | Where downloaded album art is stored; the worker writes it, the api serves it — both need access to the same directory (`docker compose` mounts a shared volume there) |
|
||||
| `IMPORT_MAX_BYTES` | api | 200 MB | Largest export file accepted |
|
||||
| `WORKER_METRICS_PORT` | worker | `9101` | The worker's Prometheus metrics port |
|
||||
| `API_BASE_URL` | ui image | `http://localhost:5050` | Where the browser reaches the API — written into `config.js` and the CSP |
|
||||
@@ -187,6 +192,10 @@ Restoring an older dump with federation on will leave followers pointed at posts
|
||||
longer exist and profile data that's gone stale — expected after any point-in-time
|
||||
restore, not a sign anything's broken.
|
||||
|
||||
The `album-art-data` volume is just a disposable cache of downloaded cover art — losing it
|
||||
isn't a data-loss event, the worker simply re-downloads anything missing the next time it's
|
||||
requested. No need to include it in backups.
|
||||
|
||||
## Upgrades
|
||||
|
||||
```sh
|
||||
|
||||
Reference in new issue
Block a user