Files
yonluandClaude Opus 5 e7748f1fd5
CI / check (push) Successful in 3m7s
CI / e2e (push) Canceled after 1m45s
feat(database): shape the library like files, and shrink the catalog
Plans 013 and 014, the album page that prompted them, and the smaller
fixes they turned up. Changelog, largest first.

## The local library is shaped like files, not like MusicBrainz

`audio_files` carries its own tags and points at `albums` and
`artists`; `file_genres` is the one real many-to-many. `recordings`,
`release_group_recordings`, `artist_credit`, `artist_credit_artist`,
`recording_genres`, `release_groups` and `release_to_rg` are gone from
the local side, and with them a six-way join in every read, a
`MIN(release_group_id)` subquery in eleven queries and a
first-credited-artist subquery in nine. Measured on a real 25,966-file
library, every many-to-many that model expressed was 1:1 in the data.

- Ownership is a file. `GetFilePathsByRecordingMBIDs`,
  `LibraryMBIDIndex.CheckMBIDs`, `collectLibraryEntities` and
  `pruneStaleLocalCrossReferences` all join `audio_files`, so the 812
  orphaned recordings, 216 release groups and 260 artists that library
  carried are now structurally impossible.
- One projection: every track query selects from the `track_metadata`
  view, one row type, one mapper. Nine hand-rolled copies had drifted
  far enough to report different years on different screens.
- `library_id = 0` means every library, so each list query exists once
  instead of scoped and unscoped with a branch at every call site.
- No migration chain. `sql/schemas/` is the one description of the
  shape; `sql/migrations/`, `applyMigrations` and `schema_migrations`
  are squashed away, along with the drift between them that had sqlc
  generating against a stale schema.
- `database.InsertTestTrack` is the one test seeder; twenty test files
  had been assembling the old FK chain each in its own order.

## The catalog stores its ids as bytes

`explore_index`'s three 36-char MBID columns and its entity-type text
are 16 raw bytes and a small integer. The table and its six indexes go
780 MB to 405 MB on a real 2,052,200-row catalog, which is why a fresh
install is ~0.6 GB rather than ~1.0 GB.

- `backend/explore/mbid.go` is the only place the encoding is known;
  everything above it speaks dashed strings.
- `CHECK(length(mbid) = 16)` makes a stringly write fail at the insert
  rather than silently returning no rows, since SQLite does not coerce
  between TEXT and BLOB.
- The importer asks the artifact what encoding it carries and converts
  on the way in, so the artifact already published keeps working and no
  format bump is needed.
- `indexRowColumns`/`scanIndexRow` replace four copies of a 22-column
  list, and `TestStoredEncodingRoundTrips` sweeps every read path.

## An album page that says how much of the album is yours

- One question, asked once: is there a file. `filePaths` is filled by a
  single batched lookup when the tracklist settles, and the badge, the
  Play count, the dimmed rows and every menu item read it — replacing
  four claims of decreasing confidence that could show a green tick on
  an album whose every action did nothing.
- Play, Play 7 of 12, or no play button at all.
- `total_tracks` on `explore_index` (~2 bytes over 400,677 release
  groups) and on `audio_files` from tags that have always carried it:
  a complete MBID-matched album now makes no catalog call at all, where
  it used to spend the most expensive request the app makes.
- A merged cluster shows the running order the most releases agree on,
  and the version list marks the release you own rather than standing a
  synthetic entry in for it.
- `AlbumReleasesFailed`: a slow fetch is no longer reported as a failed
  one by a 12-second timer.
- Rows not in the library are dimmed in place (with `aria-disabled`)
  instead of the owned ones wearing a green tick and a legend.

## Caches and cover art get ceilings

- Only the three tiers of a cover are stored; the full-resolution copy
  nothing rendered was 1,134 MB of a 1.4 GB covers directory.
- One artist portrait is downloaded and the rest are remembered as
  URLs — 4.1 GB of a 5.3 GB cache was candidates no code path reads.
- `browsedArtBudget` and `httpCacheBudget` bound what an age cannot:
  the same install held art for 5,770 artists in a 1,301-artist
  library.
- `OrphanedArtistImagesJob` joined a bare MBID onto a sharded
  directory, so it deleted the rows that were the only record of the
  files it left behind. `explore.ArtistImageDir` is that layout's one
  definition now.

## The autotag queue asks whether there is work

`tagging_items` was a row per album folder, not a queue, and no query
read the `tag_status` column that held the answer. The four queue
queries ask the files, which matters most where it is least visible:
`startPrefetch` was scoring every album in a tagged library against
MusicBrainz.

## Phantom playlist tracks resolve in place

An M3U8 imported before its files leaves phantom rows; they now match
by path and fall back to position, keep their place in the playlist
when resolved, and pair best-first so two phantoms cannot claim the
same file.

## Playing a track plays the list it is in

Double-click, and Play on a single row's menu, queue the list as
displayed with `startIndex` on that row — the album page and the track
list used to queue one track and discard the album around it. A
multi-row selection still plays exactly itself.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AfVYUVExXsx1nSWrXN8mAh
2026-08-16 13:58:15 -04:00

329 lines
12 KiB
TypeScript

// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
/**
* Service manages playlist operations.
* @module
*/
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: Unused imports
import { Call as $Call, CancellablePromise as $CancellablePromise } from "@wailsio/runtime";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: Unused imports
import * as library$0 from "../library/models.js";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: Unused imports
import * as $models from "./models.js";
/**
* AddToDefaultPlaylist adds multiple tracks to the default
* playlist, skipping any that are already present.
*/
export function AddToDefaultPlaylist(filePaths: string[] | null): $CancellablePromise<void> {
return $Call.ByID(1493850977, filePaths);
}
/**
* AddTracksToPlaylist adds one or more tracks to an existing
* playlist.
*/
export function AddTracksToPlaylist(playlistID: number, filePaths: string[] | null): $CancellablePromise<void> {
return $Call.ByID(2843242868, playlistID, filePaths);
}
/**
* CreatePlaylist creates a new empty playlist with the given name.
*/
export function CreatePlaylist(name: string): $CancellablePromise<$models.Summary> {
return $Call.ByID(4080218878, name);
}
/**
* CreatePlaylistWithTracks creates a new playlist and populates
* it with tracks.
*/
export function CreatePlaylistWithTracks(name: string, filePaths: string[] | null): $CancellablePromise<$models.Summary> {
return $Call.ByID(4079964334, name, filePaths);
}
/**
* CreateSmartPlaylist creates a new smart playlist with the given
* name and JSON rule set. The rules are validated before storage.
*/
export function CreateSmartPlaylist(name: string, rulesJSON: string): $CancellablePromise<$models.Summary> {
return $Call.ByID(2020825359, name, rulesJSON);
}
/**
* DeletePlaylist deletes a playlist and its M3U8 file.
* If the deleted playlist was the default, a new default
* playlist is automatically created.
*/
export function DeletePlaylist(playlistID: number): $CancellablePromise<void> {
return $Call.ByID(1998239209, playlistID);
}
/**
* EnsureDefaultPlaylist verifies the configured default playlist
* exists in the database. If the playlist is missing or no ID
* has been configured yet, a new playlist named "Favorites" is
* created and the config is updated.
*/
export function EnsureDefaultPlaylist(): $CancellablePromise<void> {
return $Call.ByID(3280319649);
}
/**
* EvaluateSmartPlaylist loads the rule set for a smart playlist
* from the database and evaluates it against the track library,
* returning the matching tracks.
*/
export function EvaluateSmartPlaylist(playlistID: number): $CancellablePromise<library$0.Track[] | null> {
return $Call.ByID(2192251014, playlistID);
}
/**
* FindDuplicateTracksInPlaylist checks which of the given file
* paths already exist in the specified playlist. Returns metadata
* for each duplicate and a list of non-duplicate file paths.
*/
export function FindDuplicateTracksInPlaylist(playlistID: number, filePaths: string[] | null): $CancellablePromise<$models.DuplicateCheckResult> {
return $Call.ByID(57159613, playlistID, filePaths);
}
/**
* FindPhantomMatches searches the library for matches for the
* given phantom file paths. High-confidence matches are returned
* as auto-matched pairs; the rest remain in the unmatched list.
*/
export function FindPhantomMatches(playlistID: number, phantomPaths: string[] | null): $CancellablePromise<$models.PhantomSearchResult> {
return $Call.ByID(2112903901, playlistID, phantomPaths);
}
/**
* GetAllPlaylists returns all playlists ordered by most recently
* updated.
*/
export function GetAllPlaylists(): $CancellablePromise<$models.Summary[] | null> {
return $Call.ByID(1751004770);
}
/**
* GetAllPlaylistsWithTracks returns all playlists with their
* tracks in a single call, merging phantom tracks from M3U8 files.
*/
export function GetAllPlaylistsWithTracks(): $CancellablePromise<$models.WithTracks[] | null> {
return $Call.ByID(1602859466);
}
/**
* GetDefaultPlaylistInfo returns the ID and name of the default
* playlist for display in the frontend.
*/
export function GetDefaultPlaylistInfo(): $CancellablePromise<$models.Summary> {
return $Call.ByID(845855111);
}
/**
* GetDefaultPlaylistTrackPaths returns the file paths of all
* tracks in the default playlist.
*/
export function GetDefaultPlaylistTrackPaths(): $CancellablePromise<string[] | null> {
return $Call.ByID(135237414);
}
/**
* GetPhantomCandidates returns scored candidate matches for a
* single phantom track.
*/
export function GetPhantomCandidates(playlistID: number, phantomPath: string): $CancellablePromise<$models.CandidateTrack[] | null> {
return $Call.ByID(904105323, playlistID, phantomPath);
}
/**
* GetPlaylistTracks returns all tracks in a playlist with full
* metadata, merging phantom tracks from the M3U8 file.
*/
export function GetPlaylistTracks(playlistID: number): $CancellablePromise<$models.Track[] | null> {
return $Call.ByID(3997481994, playlistID);
}
/**
* GetSmartPlaylistRules returns the raw JSON rule string for an
* existing smart playlist. This is used when the user opens the
* rule editor for an existing smart playlist.
*/
export function GetSmartPlaylistRules(playlistID: number): $CancellablePromise<string> {
return $Call.ByID(997403286, playlistID);
}
/**
* GetSmartPlaylistTracks returns the persisted snapshot of a smart
* playlist as regular playlist tracks (with resolved cover art and
* phantom entries), identical to a normal playlist. If the playlist
* has never been materialized — e.g. it predates snapshot support —
* it is evaluated and stored on first access.
*/
export function GetSmartPlaylistTracks(playlistID: number): $CancellablePromise<$models.Track[] | null> {
return $Call.ByID(2517005223, playlistID);
}
/**
* ImportPlaylist imports a playlist from an external M3U/M3U8
* file. It creates a new playlist in the DB, resolves tracks
* against the library, and saves an M3U8 file.
*/
export function ImportPlaylist(filePath: string): $CancellablePromise<$models.Summary> {
return $Call.ByID(3295216919, filePath);
}
/**
* ImportPlaylists imports multiple playlists from external M3U/M3U8
* files. Each file is imported sequentially using ImportPlaylist.
* Errors from individual imports are collected; partial success is
* possible. Returns the summaries of successfully imported playlists
* and the first error encountered (if any).
*/
export function ImportPlaylists(filePaths: string[] | null): $CancellablePromise<$models.Summary[] | null> {
return $Call.ByID(2505276524, filePaths);
}
/**
* MaterializeUnmaterializedSmartPlaylists evaluates and snapshots any
* smart playlist that has never been materialized (smart_snapshot_at
* IS NULL) — e.g. playlists created before creation-time
* materialization existed. It runs once at startup and is idempotent:
* once every smart playlist has a snapshot it becomes a no-op. Errors
* on individual playlists are logged and skipped so one bad rule set
* doesn't block the rest.
*/
export function MaterializeUnmaterializedSmartPlaylists(): $CancellablePromise<void> {
return $Call.ByID(3018316369);
}
/**
* PreviewSmartPlaylist evaluates a rule set from raw JSON without
* requiring a saved playlist. This powers live preview in the rule
* editor — the frontend sends rules as they are being edited and
* receives matching tracks immediately.
*/
export function PreviewSmartPlaylist(rulesJSON: string): $CancellablePromise<library$0.Track[] | null> {
return $Call.ByID(3006325439, rulesJSON);
}
/**
* RefreshSmartPlaylist re-evaluates a smart playlist's rules against
* the current library and replaces its persisted membership in
* playlist_tracks with the result. This is the only path that
* re-evaluates a smart playlist — opening one otherwise reads the
* stored snapshot. Triggered on rule save and by the manual Refresh
* button.
*/
export function RefreshSmartPlaylist(playlistID: number): $CancellablePromise<void> {
return $Call.ByID(2225480718, playlistID);
}
/**
* RemoveFromDefaultPlaylist removes multiple tracks from the
* default playlist.
*/
export function RemoveFromDefaultPlaylist(filePaths: string[] | null): $CancellablePromise<void> {
return $Call.ByID(619411935, filePaths);
}
/**
* RemovePhantomTracks removes phantom entries from a playlist's
* M3U8 file. Since phantom tracks have no DB rows, only the
* M3U8 file is modified.
*/
export function RemovePhantomTracks(playlistID: number, phantomPaths: string[] | null): $CancellablePromise<void> {
return $Call.ByID(823798913, playlistID, phantomPaths);
}
/**
* RemoveTracksFromPlaylist removes multiple tracks from a playlist
* by their playlist_track IDs.
*/
export function RemoveTracksFromPlaylist(playlistID: number, trackIDs: number[] | null): $CancellablePromise<void> {
return $Call.ByID(2519855654, playlistID, trackIDs);
}
/**
* RenamePlaylist renames a playlist and updates its M3U8 file.
*/
export function RenamePlaylist(playlistID: number, newName: string): $CancellablePromise<void> {
return $Call.ByID(1835045264, playlistID, newName);
}
/**
* RepopulateFromM3U re-imports tracks for playlists that have zero
* playlist_tracks rows but still have a corresponding M3U8 file.
* This recovers from a FullRescan that deleted playlist tracks
* before the ON DELETE SET NULL fix was in place. Each M3U8 entry
* is resolved against the audio_files table; unresolved entries
* become phantom tracks with metadata preserved from the M3U8.
*/
export function RepopulateFromM3U(): $CancellablePromise<void> {
return $Call.ByID(3399290718);
}
/**
* ResolvePhantomTracks replaces phantom entries in a playlist
* with real library tracks. The matches map keys are phantom
* absolute paths and values are resolved absolute paths.
*/
export function ResolvePhantomTracks(playlistID: number, matches: { [_ in string]?: string } | null): $CancellablePromise<void> {
return $Call.ByID(1239473037, playlistID, matches);
}
/**
* ResolvePhantomTracksAfterScan re-links phantom playlist tracks
* whose files now exist in the library. It iterates each playlist
* that has phantoms, reads its M3U8 file, resolves each entry
* against the current audio_files table using multi-root path
* resolution, and updates matching phantom playlist_tracks. This
* handles both pre-existing phantoms (created before migration 7,
* with NULL phantom_file_path) and new ones.
*/
export function ResolvePhantomTracksAfterScan(): $CancellablePromise<void> {
return $Call.ByID(3836161100);
}
/**
* RestoreAllPlaylists restores playlist tracks from M3U8 files.
* This is called after a full library rescan to repopulate
* playlist_tracks from the surviving M3U8 files.
*/
export function RestoreAllPlaylists(): $CancellablePromise<void> {
return $Call.ByID(453794624);
}
/**
* SearchLibrary searches the entire library by a free-text query
* for manual phantom resolution.
*/
export function SearchLibrary(query: string): $CancellablePromise<$models.CandidateTrack[] | null> {
return $Call.ByID(3912116995, query);
}
/**
* ToggleDefaultPlaylistTrack adds or removes a single track
* from the default playlist. Returns true if the track is now
* in the playlist (was added), false if it was removed.
*/
export function ToggleDefaultPlaylistTrack(filePath: string): $CancellablePromise<boolean> {
return $Call.ByID(450278306, filePath);
}
/**
* UpdateSmartPlaylistRules updates the rule set for an existing
* smart playlist. Returns an error if the playlist does not exist
* or is not a smart playlist.
*/
export function UpdateSmartPlaylistRules(playlistID: number, rulesJSON: string): $CancellablePromise<void> {
return $Call.ByID(2746792411, playlistID, rulesJSON);
}