fix(convex): stop the library scanner rewriting songs and covers every scan #91

Closed
joshuafhiggins wants to merge 1 commits from t3/fix-scanner-file-paths into main
pull from: t3/fix-scanner-file-paths
Owner

The library scanner kept writing the same data back on every scan, and in a few cases wrote the wrong data.

  • Songs with a same-titled sibling file. If an album has two files with the same title (say a copy), the existing-song branch built { [codec]: path, ...existingSong.files }, so the old path won and the same no-op patch was queued every scan. Just swapping the spread order makes it worse: the song's path then flips between the two files on alternating scans. Now we keep the tracked path while that file still exists, and otherwise merge the new path in with the right precedence.
  • Covers ping-ponged between codecs. When normal/ and lossless/ both have folder.jpg/cover.jpg, each codec pass overwrote the other's cover. That was 2 writes per artist/album on every scan. Now a cover is only replaced when the stored one is missing or no longer exists on disk.
  • Codec check was a substring match. dbCover.includes(codec) matched paths like lossless/The Abnormals/folder.jpg while scanning normal, so that artist's cover was cleared every scan. Now it checks the ${DATA_DIR}/${codec}/ prefix.
  • Untagged music got year 2026. Both clients already treat year 0 as unknown (they hide falsy years; the iOS intents hide "0"), so missing years now store 0 and an empty date instead of a made-up 01-01-2026. Existing rows aren't backfilled.

Moving or renaming a file was already handled by the removal pass and still is. It doesn't depend on the spread bug.

Verification

I ran the real scheduledUpdateLibrary handler against temp libraries of ffmpeg-tagged MP3s, with an in-memory stand-in for the library.* queries and mutations, and counted writes per scan:

Scenario Before (writes per re-scan) After
File renamed (multi-codec song) path updated, then 0 path updated, then 0
Same-titled copy added to album 1 no-op patch every scan 0
Covers in both codecs + "The Abnormals" 6 every scan, Abnormals cover null 0, Abnormals cover set
Untagged file year 2026, date 01-01-2026 year 0, date ""

pnpm --filter @otunes/convex typecheck passes.

Created with Claude Opus 5.5 in T3 Code (Cursor harness).

The library scanner kept writing the same data back on every scan, and in a few cases wrote the wrong data. - **Songs with a same-titled sibling file.** If an album has two files with the same title (say a copy), the existing-song branch built `{ [codec]: path, ...existingSong.files }`, so the old path won and the same no-op patch was queued every scan. Just swapping the spread order makes it worse: the song's path then flips between the two files on alternating scans. Now we keep the tracked path while that file still exists, and otherwise merge the new path in with the right precedence. - **Covers ping-ponged between codecs.** When `normal/` and `lossless/` both have `folder.jpg`/`cover.jpg`, each codec pass overwrote the other's cover. That was 2 writes per artist/album on every scan. Now a cover is only replaced when the stored one is missing or no longer exists on disk. - **Codec check was a substring match.** `dbCover.includes(codec)` matched paths like `lossless/The Abnormals/folder.jpg` while scanning `normal`, so that artist's cover was cleared every scan. Now it checks the `${DATA_DIR}/${codec}/` prefix. - **Untagged music got year 2026.** Both clients already treat year `0` as unknown (they hide falsy years; the iOS intents hide `"0"`), so missing years now store `0` and an empty date instead of a made-up `01-01-2026`. Existing rows aren't backfilled. Moving or renaming a file was already handled by the removal pass and still is. It doesn't depend on the spread bug. ## Verification I ran the real `scheduledUpdateLibrary` handler against temp libraries of ffmpeg-tagged MP3s, with an in-memory stand-in for the `library.*` queries and mutations, and counted writes per scan: | Scenario | Before (writes per re-scan) | After | | --- | --- | --- | | File renamed (multi-codec song) | path updated, then 0 | path updated, then 0 | | Same-titled copy added to album | 1 no-op patch every scan | 0 | | Covers in both codecs + "The Abnormals" | 6 every scan, Abnormals cover `null` | 0, Abnormals cover set | | Untagged file | year `2026`, date `01-01-2026` | year `0`, date `""` | `pnpm --filter @otunes/convex typecheck` passes. Created with Claude Opus 5.5 in T3 Code (Cursor harness).
joshuafhiggins added 1 commit 2026-11-16 12:26:27 -05:00
joshuafhiggins closed this pull request 2026-11-16 20:01:10 -05:00
joshuafhiggins reopened this pull request 2026-11-16 20:01:39 -05:00
joshuafhiggins closed this pull request 2026-11-16 20:21:45 -05:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: joshuafhiggins/otunes#91