New: Split out metadata refresh from disk rescan

pull/1689/head
ta264 5 years ago committed by Qstick
parent a2ba8e76bb
commit 95cfa0d09a

@ -11,6 +11,7 @@ using NzbDrone.Core.Housekeeping;
using NzbDrone.Core.ImportLists; using NzbDrone.Core.ImportLists;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.MediaFiles.Commands;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Music.Commands; 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(ApplicationUpdateCommand).FullName },
new ScheduledTask { Interval = 6 * 60, TypeName = typeof(CheckHealthCommand).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(RefreshArtistCommand).FullName },
new ScheduledTask { Interval = 24 * 60, TypeName = typeof(RescanFoldersCommand).FullName },
new ScheduledTask { Interval = 24 * 60, TypeName = typeof(HousekeepingCommand).FullName }, new ScheduledTask { Interval = 24 * 60, TypeName = typeof(HousekeepingCommand).FullName },
new ScheduledTask new ScheduledTask

@ -7,17 +7,22 @@ namespace NzbDrone.Core.MediaFiles.Commands
{ {
public RescanFoldersCommand() public RescanFoldersCommand()
{ {
// These are the settings used in the scheduled task
Filter = FilterFilesType.Known;
AddNewArtists = true;
} }
public RescanFoldersCommand(List<string> folders, FilterFilesType filter, List<int> artistIds) public RescanFoldersCommand(List<string> folders, FilterFilesType filter, bool addNewArtists, List<int> artistIds)
{ {
Folders = folders; Folders = folders;
Filter = filter; Filter = filter;
AddNewArtists = addNewArtists;
ArtistIds = artistIds; ArtistIds = artistIds;
} }
public List<string> Folders { get; set; } public List<string> Folders { get; set; }
public FilterFilesType Filter { get; set; } public FilterFilesType Filter { get; set; }
public bool AddNewArtists { get; set; }
public List<int> ArtistIds { get; set; } public List<int> ArtistIds { get; set; }
public override bool SendUpdatesToClient => true; public override bool SendUpdatesToClient => true;

@ -16,14 +16,13 @@ using NzbDrone.Core.MediaFiles.TrackImport;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Music; using NzbDrone.Core.Music;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.RootFolders; using NzbDrone.Core.RootFolders;
namespace NzbDrone.Core.MediaFiles namespace NzbDrone.Core.MediaFiles
{ {
public interface IDiskScanService public interface IDiskScanService
{ {
void Scan(List<string> folders = null, FilterFilesType filter = FilterFilesType.Known, List<int> artistIds = null); void Scan(List<string> folders = null, FilterFilesType filter = FilterFilesType.Known, bool addNewArtists = false, List<int> artistIds = null);
IFileInfo[] GetAudioFiles(string path, bool allDirectories = true); IFileInfo[] GetAudioFiles(string path, bool allDirectories = true);
string[] GetNonAudioFiles(string path, bool allDirectories = true); string[] GetNonAudioFiles(string path, bool allDirectories = true);
List<IFileInfo> FilterFiles(string basePath, IEnumerable<IFileInfo> files); List<IFileInfo> FilterFiles(string basePath, IEnumerable<IFileInfo> files);
@ -68,7 +67,7 @@ namespace NzbDrone.Core.MediaFiles
_logger = logger; _logger = logger;
} }
public void Scan(List<string> folders = null, FilterFilesType filter = FilterFilesType.Known, List<int> artistIds = null) public void Scan(List<string> folders = null, FilterFilesType filter = FilterFilesType.Known, bool addNewArtists = false, List<int> artistIds = null)
{ {
if (folders == null) if (folders == null)
{ {
@ -145,7 +144,7 @@ namespace NzbDrone.Core.MediaFiles
{ {
Filter = filter, Filter = filter,
IncludeExisting = true, IncludeExisting = true,
AddNewArtists = true AddNewArtists = addNewArtists
}; };
var decisions = _importDecisionMaker.GetImportDecisions(mediaFileList, null, null, config); var decisions = _importDecisionMaker.GetImportDecisions(mediaFileList, null, null, config);
@ -275,7 +274,7 @@ namespace NzbDrone.Core.MediaFiles
public void Execute(RescanFoldersCommand message) public void Execute(RescanFoldersCommand message)
{ {
Scan(message.Folders, message.Filter, message.ArtistIds); Scan(message.Folders, message.Filter, message.AddNewArtists, message.ArtistIds);
} }
} }
} }

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.MediaFiles.Commands;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
@ -33,7 +34,7 @@ namespace NzbDrone.Core.Music
tracks.ForEach(x => x.TrackFileId = 0); tracks.ForEach(x => x.TrackFileId = 0);
_trackService.SetFileIds(tracks); _trackService.SetFileIds(tracks);
_commandQueueManager.Push(new RescanFoldersCommand()); _commandQueueManager.Push(new RescanFoldersCommand(null, FilterFilesType.Matched, false, null));
} }
} }
} }

@ -318,7 +318,7 @@ namespace NzbDrone.Core.Music
{ {
bool updated = false; bool updated = false;
var updatedMusicbrainzAlbums = new HashSet<string>(); HashSet<string> updatedMusicbrainzAlbums = null;
if (lastUpdate.HasValue && lastUpdate.Value.AddDays(14) > DateTime.UtcNow) if (lastUpdate.HasValue && lastUpdate.Value.AddDays(14) > DateTime.UtcNow)
{ {

@ -285,26 +285,19 @@ namespace NzbDrone.Core.Music
_logger.Trace("Skipping rescan. Reason: not after automatic refreshes"); _logger.Trace("Skipping rescan. Reason: not after automatic refreshes");
shouldRescan = false; shouldRescan = false;
} }
else if (!infoUpdated)
if (!shouldRescan)
{ {
return; _logger.Trace("Skipping rescan. Reason: no metadata updated");
shouldRescan = false;
} }
try if (shouldRescan)
{ {
// If some metadata has been updated then rescan unmatched files. // some metadata has updated so rescan unmatched
// Otherwise only scan files that haven't been seen before. // (but don't add new artists to reduce repeated searches against api)
var filter = infoUpdated ? FilterFilesType.Matched : FilterFilesType.Known;
_logger.Trace($"InfoUpdated: {infoUpdated}, using scan filter {filter}");
var folders = _rootFolderService.All().Select(x => x.Path).ToList(); var folders = _rootFolderService.All().Select(x => x.Path).ToList();
_commandQueueManager.Push(new RescanFoldersCommand(folders, filter, artistIds)); _commandQueueManager.Push(new RescanFoldersCommand(folders, FilterFilesType.Matched, false, artistIds));
}
catch (Exception e)
{
_logger.Error(e, "Couldn't rescan");
} }
} }

@ -104,7 +104,7 @@ namespace NzbDrone.Core.RootFolders
_rootFolderRepository.Insert(rootFolder); _rootFolderRepository.Insert(rootFolder);
_commandQueueManager.Push(new RescanFoldersCommand(new List<string> { rootFolder.Path }, FilterFilesType.None, null)); _commandQueueManager.Push(new RescanFoldersCommand(new List<string> { rootFolder.Path }, FilterFilesType.None, true, null));
GetDetails(rootFolder); GetDetails(rootFolder);

Loading…
Cancel
Save