fix(library): open track details by path, not from the whole library
Track details from the queue, a playlist or a smart playlist looked the track up in libraryStore's whole-library array, and returned silently when it had not loaded, so the menu item did nothing. That dependency is also why every track was fetched eagerly at startup (20.5 MB at 26k tracks). GetTracksByPaths answers for the paths in hand, and trackCache holds the answers: bounded, coalesced into one call per task, and forgetting what the retag, removal and scan events name. Every opener, and track-details' own refresh after a save, go through it. A source sweep pins the whole-library array to the store and the Tracks view. Closes #279
This commit is contained in:
1 parent
3cddf70c4d
commit
4a9fe1d207
14 files changed
+747
-270
No files matched your search
@@ -51,12 +51,8 @@ import {
|
||||
createTrackCardDragImage,
|
||||
removeDragImage,
|
||||
} from '@utils/drag-image';
|
||||
import { libraryStore } from '@store/library-store';
|
||||
import type * as library from '@go/library/models.js';
|
||||
import { loadTrackDetails } from '@utils/lazy-track-details.js';
|
||||
import { tracksByFilePath } from '@utils/track-index.js';
|
||||
import { showTrackDetailsForPath, showBatchTrackDetailsForPaths } from '@utils/track-details-opener.js';
|
||||
import type { TrackDetails } from '@components/track-details/track-details.js';
|
||||
import type { CoverArtUrls } from '@components/track-details/track-details.js';
|
||||
import {
|
||||
creditLink,
|
||||
trackLink,
|
||||
@@ -1542,90 +1538,30 @@ export class QueuePanel
|
||||
}
|
||||
|
||||
private async openTrackDetails(index: number) {
|
||||
const queueTrack =
|
||||
this.queue.tracks[index];
|
||||
const queueTrack = this.queue.tracks[index];
|
||||
|
||||
if (!queueTrack) return;
|
||||
|
||||
const tracks =
|
||||
libraryStore.getCachedTracks();
|
||||
const track = tracks
|
||||
? tracksByFilePath(tracks).get(
|
||||
queueTrack.filePath,
|
||||
)
|
||||
: undefined;
|
||||
|
||||
if (!track) return;
|
||||
|
||||
const ready = await loadTrackDetails(
|
||||
await showTrackDetailsForPath(
|
||||
() => this.trackDetailsDialog,
|
||||
queueTrack.filePath,
|
||||
() => void this.openTrackDetails(index),
|
||||
);
|
||||
|
||||
if (!ready) return;
|
||||
|
||||
const coverArt = track.CoverArtPath
|
||||
? {
|
||||
coverArtPath: track.CoverArtPath,
|
||||
coverArtSmall: track.CoverArtSmall,
|
||||
coverArtMedium: track.CoverArtMedium,
|
||||
coverArtLarge: track.CoverArtLarge,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
this.trackDetailsDialog?.show(
|
||||
track,
|
||||
coverArt,
|
||||
);
|
||||
}
|
||||
|
||||
private async openBatchTrackDetails(
|
||||
indices: number[],
|
||||
) {
|
||||
const queueTracks = this.queue.tracks;
|
||||
const cachedTracks =
|
||||
libraryStore.getCachedTracks();
|
||||
const filePaths = indices
|
||||
.map((i) => queueTracks[i]?.filePath)
|
||||
.filter((fp): fp is string => fp != null);
|
||||
|
||||
if (!cachedTracks) return;
|
||||
|
||||
const byPath = tracksByFilePath(cachedTracks);
|
||||
const tracks = indices
|
||||
.map((i) => queueTracks[i])
|
||||
.filter((qt) => qt != null)
|
||||
.map((qt) => byPath.get(qt.filePath))
|
||||
.filter(
|
||||
(t): t is library.Track =>
|
||||
t != null,
|
||||
);
|
||||
|
||||
if (tracks.length === 0) return;
|
||||
|
||||
const ready = await loadTrackDetails(
|
||||
await showBatchTrackDetailsForPaths(
|
||||
() => this.trackDetailsDialog,
|
||||
filePaths,
|
||||
() => void this.openBatchTrackDetails(indices),
|
||||
);
|
||||
|
||||
if (!ready) return;
|
||||
|
||||
const first = tracks[0]!;
|
||||
const albumNames = new Set(tracks.map((t) => t.Album));
|
||||
let coverArt: CoverArtUrls | null = null;
|
||||
let coverArtMixed = false;
|
||||
|
||||
if (albumNames.size === 1 && first.CoverArtPath) {
|
||||
coverArt = {
|
||||
coverArtPath: first.CoverArtPath,
|
||||
coverArtSmall: first.CoverArtSmall,
|
||||
coverArtMedium: first.CoverArtMedium,
|
||||
coverArtLarge: first.CoverArtLarge,
|
||||
};
|
||||
} else if (albumNames.size > 1) {
|
||||
coverArtMixed = true;
|
||||
}
|
||||
|
||||
this.trackDetailsDialog?.showBatch(
|
||||
tracks,
|
||||
coverArt,
|
||||
coverArtMixed,
|
||||
);
|
||||
}
|
||||
|
||||
private onContextPlaylistActionComplete = () => {
|
||||
|
||||
Reference in new issue
Block a user