music indexer: 3s progress heartbeat log during a build

A long full rebuild logged only "resync started" then nothing until "done".
Add a console heartbeat (throttled to 3s, piggybacked on emitProgress) showing
folders/built/skipped/tracks/videos/posters/lyrics counts + the current path, so
progress is visible in the pm2 logs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-27 15:15:35 +00:00
co-authored by Claude Opus 4.8
parent 219f93a831
commit 43135865e2
+10
View File
@@ -202,6 +202,7 @@ export function buildReport(s: IndexStatus = status): IndexReport {
type ProgressListener = (s: IndexStatus) => void;
const listeners = new Set<ProgressListener>();
let lastEmit = 0;
let lastLog = 0;
export function onIndexProgress(cb: ProgressListener): () => void {
listeners.add(cb);
@@ -211,6 +212,15 @@ export function onIndexProgress(cb: ProgressListener): () => void {
/** Notify subscribers of progress; throttled to ~200ms unless `force` (e.g. terminal 'done'). */
function emitProgress(force = false): void {
const now = Date.now();
// Console heartbeat (throttled to 3s, independent of the SSE cadence) so a long build shows life.
if (now - lastLog >= 3000) {
lastLog = now;
console.log(
`[music] … ${status.foldersScanned} folders · ${status.albumsBuilt} built/${status.albumsSkipped} skipped · ` +
`${status.tracksIndexed} tracks · ${status.videosIndexed} videos · ${status.postersSaved} posters · ` +
`${status.lyricsIndexed} lyrics — ${status.currentPath}`,
);
}
if (!force && now - lastEmit < 200) return;
lastEmit = now;
const snap = getIndexStatus();