New: Split out metadata refresh from disk rescan

This commit is contained in:
ta264 2020-02-27 21:27:06 +00:00 committed by Qstick
parent a2ba8e76bb
commit 95cfa0d09a
7 changed files with 23 additions and 23 deletions

View File

@ -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

View File

@ -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<string> folders, FilterFilesType filter, List<int> artistIds)
public RescanFoldersCommand(List<string> folders, FilterFilesType filter, bool addNewArtists, List<int> artistIds)
{
Folders = folders;
Filter = filter;
AddNewArtists = addNewArtists;
ArtistIds = artistIds;
}
public List<string> Folders { get; set; }
public FilterFilesType Filter { get; set; }
public bool AddNewArtists { get; set; }
public List<int> ArtistIds { get; set; }
public override bool SendUpdatesToClient => true;

View File

@ -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<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);
string[] GetNonAudioFiles(string path, bool allDirectories = true);
List<IFileInfo> FilterFiles(string basePath, IEnumerable<IFileInfo> files);
@ -68,7 +67,7 @@ namespace NzbDrone.Core.MediaFiles
_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)
{
@ -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);
}
}
}

View File

@ -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));
}
}
}

View File

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

View File

@ -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));
}
}

View File

@ -104,7 +104,7 @@ namespace NzbDrone.Core.RootFolders
_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);