From 1e5c3db9eba730fe8b52995e5c699c22983fa62a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 23 Jun 2017 12:04:45 -0400 Subject: support individual library refreshing --- .../Library/LibraryManager.cs | 40 ++++++++------- .../Library/Validators/PeopleValidator.cs | 4 -- .../Library/Validators/YearsPostScanTask.cs | 57 ---------------------- 3 files changed, 23 insertions(+), 78 deletions(-) delete mode 100644 Emby.Server.Implementations/Library/Validators/YearsPostScanTask.cs (limited to 'Emby.Server.Implementations/Library') diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index 15efd3d39..1a909549e 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -462,7 +462,7 @@ namespace Emby.Server.Implementations.Library if (parent != null) { - await parent.ValidateChildren(new Progress(), CancellationToken.None, new MetadataRefreshOptions(_fileSystem), false).ConfigureAwait(false); + await parent.ValidateChildren(new SimpleProgress(), CancellationToken.None, new MetadataRefreshOptions(_fileSystem), false).ConfigureAwait(false); } } else if (parent != null) @@ -1113,13 +1113,13 @@ namespace Emby.Server.Implementations.Library progress.Report(.5); // Start by just validating the children of the root, but go no further - await RootFolder.ValidateChildren(new Progress(), cancellationToken, new MetadataRefreshOptions(_fileSystem), recursive: false); + await RootFolder.ValidateChildren(new SimpleProgress(), cancellationToken, new MetadataRefreshOptions(_fileSystem), recursive: false); progress.Report(1); await GetUserRootFolder().RefreshMetadata(cancellationToken).ConfigureAwait(false); - await GetUserRootFolder().ValidateChildren(new Progress(), cancellationToken, new MetadataRefreshOptions(_fileSystem), recursive: false).ConfigureAwait(false); + await GetUserRootFolder().ValidateChildren(new SimpleProgress(), cancellationToken, new MetadataRefreshOptions(_fileSystem), recursive: false).ConfigureAwait(false); progress.Report(2); // Quickly scan CollectionFolders for changes @@ -1204,25 +1204,24 @@ namespace Emby.Server.Implementations.Library /// Gets the default view. /// /// IEnumerable{VirtualFolderInfo}. - public IEnumerable GetVirtualFolders() + public List GetVirtualFolders() { - return GetView(ConfigurationManager.ApplicationPaths.DefaultUserViewsPath); + return GetVirtualFolders(false); } - /// - /// Gets the view. - /// - /// The path. - /// IEnumerable{VirtualFolderInfo}. - private IEnumerable GetView(string path) + public List GetVirtualFolders(bool includeRefreshState) { var topLibraryFolders = GetUserRootFolder().Children.ToList(); - return _fileSystem.GetDirectoryPaths(path) - .Select(dir => GetVirtualFolderInfo(dir, topLibraryFolders)); + var refreshQueue = includeRefreshState ? _providerManagerFactory().GetRefreshQueue() : null; + + return _fileSystem.GetDirectoryPaths(ConfigurationManager.ApplicationPaths.DefaultUserViewsPath) + .Select(dir => GetVirtualFolderInfo(dir, topLibraryFolders, refreshQueue)) + .OrderBy(i => i.Name) + .ToList(); } - private VirtualFolderInfo GetVirtualFolderInfo(string dir, List allCollectionFolders) + private VirtualFolderInfo GetVirtualFolderInfo(string dir, List allCollectionFolders, Dictionary refreshQueue) { var info = new VirtualFolderInfo { @@ -1248,6 +1247,13 @@ namespace Emby.Server.Implementations.Library { info.ItemId = libraryFolder.Id.ToString("N"); info.LibraryOptions = GetLibraryOptions(libraryFolder); + + if (refreshQueue != null) + { + info.RefreshProgress = libraryFolder.GetRefreshProgress(); + + info.RefreshStatus = info.RefreshProgress.HasValue ? "Active" : refreshQueue.ContainsKey(libraryFolder.Id) ? "Queued" : "Idle"; + } } return info; @@ -2947,7 +2953,7 @@ namespace Emby.Server.Implementations.Library // No need to start if scanning the library because it will handle it if (refreshLibrary) { - ValidateMediaLibrary(new Progress(), CancellationToken.None); + ValidateMediaLibrary(new SimpleProgress(), CancellationToken.None); } else { @@ -3075,7 +3081,7 @@ namespace Emby.Server.Implementations.Library private void SyncLibraryOptionsToLocations(string virtualFolderPath, LibraryOptions options) { var topLibraryFolders = GetUserRootFolder().Children.ToList(); - var info = GetVirtualFolderInfo(virtualFolderPath, topLibraryFolders); + var info = GetVirtualFolderInfo(virtualFolderPath, topLibraryFolders, null); if (info.Locations.Count > 0 && info.Locations.Count != options.PathInfos.Length) { @@ -3125,7 +3131,7 @@ namespace Emby.Server.Implementations.Library // No need to start if scanning the library because it will handle it if (refreshLibrary) { - ValidateMediaLibrary(new Progress(), CancellationToken.None); + ValidateMediaLibrary(new SimpleProgress(), CancellationToken.None); } else { diff --git a/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs b/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs index ef3b86abf..c2eb30ee4 100644 --- a/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs +++ b/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs @@ -55,10 +55,6 @@ namespace Emby.Server.Implementations.Library.Validators /// Task. public async Task ValidatePeople(CancellationToken cancellationToken, IProgress progress) { - var innerProgress = new ActionableProgress(); - - innerProgress.RegisterAction(pct => progress.Report(pct * .15)); - var people = _libraryManager.GetPeople(new InternalPeopleQuery()); var dict = new Dictionary(StringComparer.OrdinalIgnoreCase); diff --git a/Emby.Server.Implementations/Library/Validators/YearsPostScanTask.cs b/Emby.Server.Implementations/Library/Validators/YearsPostScanTask.cs deleted file mode 100644 index 4afb4c04a..000000000 --- a/Emby.Server.Implementations/Library/Validators/YearsPostScanTask.cs +++ /dev/null @@ -1,57 +0,0 @@ -using MediaBrowser.Controller.Library; -using MediaBrowser.Model.Logging; -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace Emby.Server.Implementations.Library.Validators -{ - public class YearsPostScanTask : ILibraryPostScanTask - { - private readonly ILibraryManager _libraryManager; - private readonly ILogger _logger; - - public YearsPostScanTask(ILibraryManager libraryManager, ILogger logger) - { - _libraryManager = libraryManager; - _logger = logger; - } - - public async Task Run(IProgress progress, CancellationToken cancellationToken) - { - var yearNumber = 1900; - var maxYear = DateTime.UtcNow.Year + 3; - var count = maxYear - yearNumber + 1; - var numComplete = 0; - - while (yearNumber < maxYear) - { - cancellationToken.ThrowIfCancellationRequested(); - - try - { - var year = _libraryManager.GetYear(yearNumber); - - await year.RefreshMetadata(cancellationToken).ConfigureAwait(false); - } - catch (OperationCanceledException) - { - // Don't clutter the log - throw; - } - catch (Exception ex) - { - _logger.ErrorException("Error refreshing year {0}", ex, yearNumber); - } - - numComplete++; - double percent = numComplete; - percent /= count; - percent *= 100; - - progress.Report(percent); - yearNumber++; - } - } - } -} -- cgit v1.2.3