Skip to content

Commit

Permalink
Use a cached temporary track when looking up cover arts form file met…
Browse files Browse the repository at this point in the history
…adata. This fixes a priority inversion when scrolling the library mixxxdj#11128
  • Loading branch information
daschuer committed Oct 4, 2024
1 parent 4555133 commit 357d1d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
23 changes: 8 additions & 15 deletions src/sources/soundsourceproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ importTrackMetadataAndCoverImageUnavailable() {
//static
std::pair<mixxx::MetadataSource::ImportResult, QDateTime>
SoundSourceProxy::importTrackMetadataAndCoverImageFromFile(
mixxx::FileAccess trackFileAccess,
const mixxx::FileAccess& trackFileAccess,
mixxx::TrackMetadata* pTrackMetadata,
QImage* pCoverImage,
bool resetMissingTagMetadata) {
Expand All @@ -553,20 +553,13 @@ SoundSourceProxy::importTrackMetadataAndCoverImageFromFile(
// https://github.com/mixxxdj/mixxx/issues/9944
return importTrackMetadataAndCoverImageUnavailable();
}
TrackPointer pTrack;
// Lock the global track cache while accessing the file to ensure
// that no metadata is written. Since locking individual files
// is not possible the whole cache has to be locked.
GlobalTrackCacheLocker locker;
pTrack = locker.lookupTrackByRef(TrackRef::fromFileInfo(trackFileAccess.info()));
if (pTrack) {
// We can safely unlock the cache if the track object is already cached.
locker.unlockCache();
} else {
// If the track object is not cached we need to keep the cache
// locked and create a temporary track object instead.
pTrack = Track::newTemporary(std::move(trackFileAccess));
}
// Since we want to read the cover only, use a temporary track
// that is discarded in an incomplet state without saving to library or
// track meta data. Lock the track via the global track cache while
// accessing the file to ensure that no metadata is written by another trhead.
bool temporary = true;
auto cacheResolver = GlobalTrackCacheResolver(trackFileAccess, temporary);
TrackPointer pTrack = cacheResolver.getTrack();
return SoundSourceProxy(pTrack).importTrackMetadataAndCoverImage(
pTrackMetadata,
pCoverImage,
Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourceproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class SoundSourceProxy {
/// while reading.
static std::pair<mixxx::MetadataSource::ImportResult, QDateTime>
importTrackMetadataAndCoverImageFromFile(
mixxx::FileAccess trackFileAccess,
const mixxx::FileAccess& trackFileAccess,
mixxx::TrackMetadata* pTrackMetadata,
QImage* pCoverImage,
bool resetMissingTagMetadata);
Expand Down

0 comments on commit 357d1d1

Please sign in to comment.