diff --git a/src/NzbDrone.Core/Jobs/TaskManager.cs b/src/NzbDrone.Core/Jobs/TaskManager.cs index 244b647df..bf922a79c 100644 --- a/src/NzbDrone.Core/Jobs/TaskManager.cs +++ b/src/NzbDrone.Core/Jobs/TaskManager.cs @@ -11,6 +11,7 @@ using NzbDrone.Core.Housekeeping; using NzbDrone.Core.ImportLists; using NzbDrone.Core.Indexers; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Music.Commands; @@ -65,6 +66,7 @@ namespace NzbDrone.Core.Jobs new ScheduledTask { Interval = 6 * 60, TypeName = typeof(ApplicationUpdateCommand).FullName }, new ScheduledTask { Interval = 6 * 60, TypeName = typeof(CheckHealthCommand).FullName }, new ScheduledTask { Interval = 24 * 60, TypeName = typeof(RefreshArtistCommand).FullName }, + new ScheduledTask { Interval = 24 * 60, TypeName = typeof(RescanFoldersCommand).FullName }, new ScheduledTask { Interval = 24 * 60, TypeName = typeof(HousekeepingCommand).FullName }, new ScheduledTask diff --git a/src/NzbDrone.Core/MediaFiles/Commands/RescanFoldersCommand.cs b/src/NzbDrone.Core/MediaFiles/Commands/RescanFoldersCommand.cs index 45519130d..e63a70135 100644 --- a/src/NzbDrone.Core/MediaFiles/Commands/RescanFoldersCommand.cs +++ b/src/NzbDrone.Core/MediaFiles/Commands/RescanFoldersCommand.cs @@ -7,17 +7,22 @@ namespace NzbDrone.Core.MediaFiles.Commands { public RescanFoldersCommand() { + // These are the settings used in the scheduled task + Filter = FilterFilesType.Known; + AddNewArtists = true; } - public RescanFoldersCommand(List folders, FilterFilesType filter, List artistIds) + public RescanFoldersCommand(List folders, FilterFilesType filter, bool addNewArtists, List artistIds) { Folders = folders; Filter = filter; + AddNewArtists = addNewArtists; ArtistIds = artistIds; } public List Folders { get; set; } public FilterFilesType Filter { get; set; } + public bool AddNewArtists { get; set; } public List ArtistIds { get; set; } public override bool SendUpdatesToClient => true; diff --git a/src/NzbDrone.Core/MediaFiles/DiskScanService.cs b/src/NzbDrone.Core/MediaFiles/DiskScanService.cs index 1fd5477ff..62f1f1664 100644 --- a/src/NzbDrone.Core/MediaFiles/DiskScanService.cs +++ b/src/NzbDrone.Core/MediaFiles/DiskScanService.cs @@ -16,14 +16,13 @@ using NzbDrone.Core.MediaFiles.TrackImport; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Music; -using NzbDrone.Core.Parser.Model; using NzbDrone.Core.RootFolders; namespace NzbDrone.Core.MediaFiles { public interface IDiskScanService { - void Scan(List folders = null, FilterFilesType filter = FilterFilesType.Known, List artistIds = null); + void Scan(List folders = null, FilterFilesType filter = FilterFilesType.Known, bool addNewArtists = false, List artistIds = null); IFileInfo[] GetAudioFiles(string path, bool allDirectories = true); string[] GetNonAudioFiles(string path, bool allDirectories = true); List FilterFiles(string basePath, IEnumerable files); @@ -68,7 +67,7 @@ namespace NzbDrone.Core.MediaFiles _logger = logger; } - public void Scan(List folders = null, FilterFilesType filter = FilterFilesType.Known, List artistIds = null) + public void Scan(List folders = null, FilterFilesType filter = FilterFilesType.Known, bool addNewArtists = false, List artistIds = null) { if (folders == null) { @@ -145,7 +144,7 @@ namespace NzbDrone.Core.MediaFiles { Filter = filter, IncludeExisting = true, - AddNewArtists = true + AddNewArtists = addNewArtists }; var decisions = _importDecisionMaker.GetImportDecisions(mediaFileList, null, null, config); @@ -275,7 +274,7 @@ namespace NzbDrone.Core.MediaFiles public void Execute(RescanFoldersCommand message) { - Scan(message.Folders, message.Filter, message.ArtistIds); + Scan(message.Folders, message.Filter, message.AddNewArtists, message.ArtistIds); } } } diff --git a/src/NzbDrone.Core/Music/Services/AlbumEditedService.cs b/src/NzbDrone.Core/Music/Services/AlbumEditedService.cs index f62a5e5d6..13cccc4a5 100644 --- a/src/NzbDrone.Core/Music/Services/AlbumEditedService.cs +++ b/src/NzbDrone.Core/Music/Services/AlbumEditedService.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; @@ -33,7 +34,7 @@ namespace NzbDrone.Core.Music tracks.ForEach(x => x.TrackFileId = 0); _trackService.SetFileIds(tracks); - _commandQueueManager.Push(new RescanFoldersCommand()); + _commandQueueManager.Push(new RescanFoldersCommand(null, FilterFilesType.Matched, false, null)); } } } diff --git a/src/NzbDrone.Core/Music/Services/RefreshAlbumService.cs b/src/NzbDrone.Core/Music/Services/RefreshAlbumService.cs index aaa6169eb..2c536ffa9 100644 --- a/src/NzbDrone.Core/Music/Services/RefreshAlbumService.cs +++ b/src/NzbDrone.Core/Music/Services/RefreshAlbumService.cs @@ -318,7 +318,7 @@ namespace NzbDrone.Core.Music { bool updated = false; - var updatedMusicbrainzAlbums = new HashSet(); + HashSet updatedMusicbrainzAlbums = null; if (lastUpdate.HasValue && lastUpdate.Value.AddDays(14) > DateTime.UtcNow) { diff --git a/src/NzbDrone.Core/Music/Services/RefreshArtistService.cs b/src/NzbDrone.Core/Music/Services/RefreshArtistService.cs index bf6bbb89e..987d98d4e 100644 --- a/src/NzbDrone.Core/Music/Services/RefreshArtistService.cs +++ b/src/NzbDrone.Core/Music/Services/RefreshArtistService.cs @@ -285,26 +285,19 @@ namespace NzbDrone.Core.Music _logger.Trace("Skipping rescan. Reason: not after automatic refreshes"); shouldRescan = false; } - - if (!shouldRescan) + else if (!infoUpdated) { - return; + _logger.Trace("Skipping rescan. Reason: no metadata updated"); + shouldRescan = false; } - try + if (shouldRescan) { - // If some metadata has been updated then rescan unmatched files. - // Otherwise only scan files that haven't been seen before. - var filter = infoUpdated ? FilterFilesType.Matched : FilterFilesType.Known; - _logger.Trace($"InfoUpdated: {infoUpdated}, using scan filter {filter}"); - + // some metadata has updated so rescan unmatched + // (but don't add new artists to reduce repeated searches against api) var folders = _rootFolderService.All().Select(x => x.Path).ToList(); - _commandQueueManager.Push(new RescanFoldersCommand(folders, filter, artistIds)); - } - catch (Exception e) - { - _logger.Error(e, "Couldn't rescan"); + _commandQueueManager.Push(new RescanFoldersCommand(folders, FilterFilesType.Matched, false, artistIds)); } } diff --git a/src/NzbDrone.Core/RootFolders/RootFolderService.cs b/src/NzbDrone.Core/RootFolders/RootFolderService.cs index 541e7cb06..368d668b9 100644 --- a/src/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/src/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -104,7 +104,7 @@ namespace NzbDrone.Core.RootFolders _rootFolderRepository.Insert(rootFolder); - _commandQueueManager.Push(new RescanFoldersCommand(new List { rootFolder.Path }, FilterFilesType.None, null)); + _commandQueueManager.Push(new RescanFoldersCommand(new List { rootFolder.Path }, FilterFilesType.None, true, null)); GetDetails(rootFolder);