From dcca2b5a1a22c6fed2a135bf09cf0709f7345b02 Mon Sep 17 00:00:00 2001 From: ta264 Date: Thu, 1 Aug 2019 22:22:28 +0100 Subject: [PATCH] Fixed: Don't re-read file tags if possible --- .../Identification/IdentificationService.cs | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/NzbDrone.Core/MediaFiles/TrackImport/Identification/IdentificationService.cs b/src/NzbDrone.Core/MediaFiles/TrackImport/Identification/IdentificationService.cs index 06a183291..2b56e7d11 100644 --- a/src/NzbDrone.Core/MediaFiles/TrackImport/Identification/IdentificationService.cs +++ b/src/NzbDrone.Core/MediaFiles/TrackImport/Identification/IdentificationService.cs @@ -173,17 +173,19 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification return false; } - private List ToLocalTrack(IEnumerable trackfiles) + private List ToLocalTrack(IEnumerable trackfiles, LocalAlbumRelease localRelease) { - var localTracks = trackfiles.Select(x => new LocalTrack { - Path = x.Path, - Size = x.Size, - Modified = x.Modified, - FileTrackInfo = _audioTagService.ReadTags(x.Path), - ExistingFile = true, - AdditionalFile = true, - Quality = x.Quality - }) + var scanned = trackfiles.Join(localRelease.LocalTracks, t => t.Path, l => l.Path, (track, localTrack) => localTrack); + var toScan = trackfiles.ExceptBy(t => t.Path, scanned, s => s.Path, StringComparer.InvariantCulture); + var localTracks = scanned.Concat(toScan.Select(x => new LocalTrack { + Path = x.Path, + Size = x.Size, + Modified = x.Modified, + FileTrackInfo = _audioTagService.ReadTags(x.Path), + ExistingFile = true, + AdditionalFile = true, + Quality = x.Quality + })) .ToList(); localTracks.ForEach(x => _augmentingService.Augment(x, true)); @@ -218,7 +220,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification // convert all the TrackFiles that represent extra files to List var allLocalTracks = ToLocalTrack(candidateReleases .SelectMany(x => x.ExistingTracks) - .DistinctBy(x => x.Path)); + .DistinctBy(x => x.Path), localAlbumRelease); _logger.Debug($"Retrieved {allTracks.Count} possible tracks in {watch.ElapsedMilliseconds}ms"); @@ -242,7 +244,8 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification allLocalTracks.AddRange(ToLocalTrack(newCandidates .SelectMany(x => x.ExistingTracks) .DistinctBy(x => x.Path) - .ExceptBy(x => x.Path, allLocalTracks, x => x.Path, PathEqualityComparer.Instance))); + .ExceptBy(x => x.Path, allLocalTracks, x => x.Path, PathEqualityComparer.Instance), + localAlbumRelease)); } // fingerprint all the local files in candidates we might be matching against