mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07:00
Fixed: Speed up track grouping
Don't repeatedly calculate base directories and use simpler path equality since we know paths come from the same source.
This commit is contained in:
parent
3c1b3434c7
commit
5f679c5f58
1 changed files with 10 additions and 6 deletions
|
@ -5,6 +5,7 @@ using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Common.Instrumentation;
|
using NzbDrone.Common.Instrumentation;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
@ -176,15 +177,16 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification
|
||||||
// and group them.
|
// and group them.
|
||||||
|
|
||||||
// we only bother doing this for the immediate parent directory.
|
// we only bother doing this for the immediate parent directory.
|
||||||
var paths = tracks.Select(x => x.Path);
|
var trackFolders = tracks.Select(x => Tuple.Create(x, Path.GetDirectoryName(x.Path)));
|
||||||
var folders = paths.Select(x => Path.GetDirectoryName(x)).Distinct().ToList();
|
|
||||||
folders.Sort();
|
var distinctFolders = trackFolders.Select(x => x.Item2).Distinct().ToList();
|
||||||
|
distinctFolders.Sort();
|
||||||
|
|
||||||
_logger.Trace("Folders:\n{0}", string.Join("\n", folders));
|
_logger.Trace("Folders:\n{0}", string.Join("\n", distinctFolders));
|
||||||
|
|
||||||
Regex subdirRegex = null;
|
Regex subdirRegex = null;
|
||||||
var output = new List<LocalTrack>();
|
var output = new List<LocalTrack>();
|
||||||
foreach (var folder in folders)
|
foreach (var folder in distinctFolders)
|
||||||
{
|
{
|
||||||
if (subdirRegex != null)
|
if (subdirRegex != null)
|
||||||
{
|
{
|
||||||
|
@ -208,7 +210,9 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification
|
||||||
|
|
||||||
// reset and put current folder into output
|
// reset and put current folder into output
|
||||||
subdirRegex = null;
|
subdirRegex = null;
|
||||||
output.AddRange(tracks.Where(x => PathEqualityComparer.Instance.Equals(Path.GetDirectoryName(x.Path), folder)));
|
var currentTracks = trackFolders.Where(x => x.Item2.Equals(folder, DiskProviderBase.PathStringComparison))
|
||||||
|
.Select(x => x.Item1);
|
||||||
|
output.AddRange(currentTracks);
|
||||||
|
|
||||||
// check if the start of another multi disc match
|
// check if the start of another multi disc match
|
||||||
foreach (var marker in multiDiscMarkers)
|
foreach (var marker in multiDiscMarkers)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue