aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
diff options
context:
space:
mode:
authorEric Reed <ebr@mediabrowser3.com>2013-05-25 11:51:09 -0400
committerEric Reed <ebr@mediabrowser3.com>2013-05-25 11:51:09 -0400
commit873be2f284632287dba5401fc78eb4828c1f2cd1 (patch)
treec41e8628c3b27939fa3f96b4de36d7e469d0eaa8 /MediaBrowser.Server.Implementations/Library/LibraryManager.cs
parent7162566f56549d820c865abdbc0c336a92550032 (diff)
parent5c5ec6e644921b8f31f0fce74aadb59bf0fef99a (diff)
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library/LibraryManager.cs')
-rw-r--r--MediaBrowser.Server.Implementations/Library/LibraryManager.cs66
1 files changed, 53 insertions, 13 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
index af0212738..ae0607689 100644
--- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
@@ -252,7 +252,7 @@ namespace MediaBrowser.Server.Implementations.Library
var newSeasonZeroName = ConfigurationManager.Configuration.SeasonZeroDisplayName;
var seasonZeroNameChanged = !string.Equals(_seasonZeroDisplayName, newSeasonZeroName, StringComparison.CurrentCulture);
-
+
RecordConfigurationValues(config);
Task.Run(async () =>
@@ -895,30 +895,28 @@ namespace MediaBrowser.Server.Implementations.Library
await RootFolder.RefreshMetadata(cancellationToken).ConfigureAwait(false);
+ progress.Report(.5);
+
// Start by just validating the children of the root, but go no further
await RootFolder.ValidateChildren(new Progress<double>(), cancellationToken, recursive: false);
+ progress.Report(1);
+
foreach (var folder in _userManager.Users.Select(u => u.RootFolder).Distinct())
{
await ValidateCollectionFolders(folder, cancellationToken).ConfigureAwait(false);
}
+ progress.Report(2);
+
// Run prescan tasks
- foreach (var task in PrescanTasks)
- {
- try
- {
- await task.Run(new Progress<double>(), cancellationToken);
- }
- catch (Exception ex)
- {
- _logger.ErrorException("Error running prescan task", ex);
- }
- }
+ await RunPrescanTasks(progress, cancellationToken).ConfigureAwait(false);
+ progress.Report(15);
+
var innerProgress = new ActionableProgress<double>();
- innerProgress.RegisterAction(pct => progress.Report(pct * .8));
+ innerProgress.RegisterAction(pct => progress.Report(15 + pct * .65));
// Now validate the entire media library
await RootFolder.ValidateChildren(innerProgress, cancellationToken, recursive: true).ConfigureAwait(false);
@@ -933,6 +931,48 @@ namespace MediaBrowser.Server.Implementations.Library
}
/// <summary>
+ /// Runs the prescan tasks.
+ /// </summary>
+ /// <param name="progress">The progress.</param>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>Task.</returns>
+ private async Task RunPrescanTasks(IProgress<double> progress, CancellationToken cancellationToken)
+ {
+ var prescanTasks = PrescanTasks.ToList();
+ var progressDictionary = new Dictionary<ILibraryPrescanTask, double>();
+
+ var tasks = prescanTasks.Select(i => Task.Run(async () =>
+ {
+ var innerProgress = new ActionableProgress<double>();
+
+ innerProgress.RegisterAction(pct =>
+ {
+ lock (progressDictionary)
+ {
+ progressDictionary[i] = pct;
+
+ double percent = progressDictionary.Values.Sum();
+ percent /= prescanTasks.Count;
+
+ progress.Report(2 + percent * .13);
+ }
+ });
+
+ try
+ {
+ await i.Run(innerProgress, cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error running prescan task", ex);
+ }
+ }));
+
+ // Run prescan tasks
+ await Task.WhenAll(tasks).ConfigureAwait(false);
+ }
+
+ /// <summary>
/// Validates only the collection folders for a User and goes no further
/// </summary>
/// <param name="userRootFolder">The user root folder.</param>