Skip to content

Index sorted albums immediately when a sort succeeds

jedmund requested to merge jedmund/index-on-sort into main

Summary

Follow-up to PR #29: the new Artists view reads counts and the Sorted section from the sortedAlbums table, but executeSort only updated albums.statussortedAlbums stayed stale until a full sorted-directory rescan. So after sorting an album from /artists, the pending count dropped (from albums.status) but the sorted count didn't increase and the newly-sorted album didn't appear in the Sorted section.

Fix: insert a sortedAlbums row as part of executeSort, right after the disk copy and status update. The row mirrors exactly what scanSortedDirectory would produce — same folder-name regex, same Various Artists handling for Soundtracks — so a subsequent full rescan produces an identical row with no drift. onConflictDoUpdate on folderPath handles the overwrite path cleanly.

With this, /artists's handleSorted (which already clears its cache and refetches) now sees correct counts and section contents immediately, with no button and no polling needed.

Test plan

  • pnpm run build passes
  • Sort an album from /artists → Unsorted section drops it, Sorted section shows it, counts update
  • Sort an album from / (home) → navigate to /artists → counts reflect the sort without a manual refresh
  • Overwrite an existing sorted album (sort with overwriteExisting: true to the same target path) → sortedAlbums row updates cleanly via onConflictDoUpdate
  • Sort a Soundtrack → row is inserted with artist: 'Various Artists' to match scanSortedDirectory
  • Run a full sorted-directory rescan afterwards → no drift, sortedAlbums stays identical

Merge request reports

Loading