music: /manifest is a pure read — never triggers a (re)build
Reading the manifest (which every app refresh hits) used to call ensureIndexFresh(), kicking off a debounced rebuild — and after the CACHE_VERSION bump that meant a plain refresh could launch a full library rebuild. Make reads side-effect-free: /manifest now just returns the last completed index. Builds are explicit only (POST /reindex or the SSE stream); pick up disk changes by reindexing. Removes the now-unused ensureIndexFresh + lastBuildFinishedAt, and drops /manifest from the 30-min per-request timeout extension (both hops) since it no longer blocks on a build. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,6 @@ import { createSidecarConnector } from '../connect';
|
||||
import { streamAudioFile } from './stream-audio';
|
||||
import {
|
||||
reindexNow,
|
||||
ensureIndexFresh,
|
||||
getIndexStatus,
|
||||
getManifest,
|
||||
albumVersion,
|
||||
@@ -34,8 +33,8 @@ const DATA_PATH = process.env.DATA_PATH ?? join(process.cwd(), 'data');
|
||||
//
|
||||
// GET /stream?path=<home-relative> audio with Range→206 (Content-Range/Length/Accept-Ranges)
|
||||
// + `X-Audio-Duration` (seconds, ffprobe). 400/404/416.
|
||||
// GET /manifest ensures a fresh index (debounced rebuild) then returns
|
||||
// { version, generatedAt, albums: { "<rel>": { v, cover, tracks, disco? } } }
|
||||
// GET /manifest pure read of the last completed index (NO build triggered) —
|
||||
// { version, generatedAt, albums: { "<rel>": { v, cover, tracks, videos?, disco? } } }
|
||||
// GET /meta?path=<rel> album meta.json (IndexMeta). ETag: <v>; If-None-Match → 304.
|
||||
// GET /cover?path=<rel> compressed cover.jpg. ETag: <v>; If-None-Match → 304.
|
||||
// GET /poster?path=<rel>&file=<video> compressed video poster (frame grab). ETag: <v>; 304. 404 if none.
|
||||
@@ -80,8 +79,8 @@ const server = Bun.serve({
|
||||
async fetch(req, server) {
|
||||
const url = new URL(req.url);
|
||||
// A from-scratch reindex can take many minutes with no bytes flowing on the triggering request.
|
||||
// Give the build-triggering + progress endpoints a 30-min idle timeout so they aren't dropped.
|
||||
if (url.pathname === '/reindex' || url.pathname === '/manifest' || url.pathname === '/reindex/stream') {
|
||||
// Give the build endpoints a 30-min idle timeout so they aren't dropped (/manifest is a pure read now).
|
||||
if (url.pathname === '/reindex' || url.pathname === '/reindex/stream') {
|
||||
server.timeout(req, 1800);
|
||||
}
|
||||
const json = (data: unknown, init?: ResponseInit) =>
|
||||
@@ -157,9 +156,8 @@ const server = Bun.serve({
|
||||
|
||||
// ── Sync surface ──
|
||||
if (url.pathname === '/manifest') {
|
||||
// Every app refresh funnels through here, so rebuild the index first (debounced) — this is what
|
||||
// makes on-disk changes show up on a plain refresh, not only via the explicit reindex sheet.
|
||||
await ensureIndexFresh();
|
||||
// Pure read — returns the last completed index. It does NOT trigger a build (that could kick off a
|
||||
// long/full rebuild on a plain app refresh); use POST /reindex explicitly to pick up disk changes.
|
||||
return json(await getManifest());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user