aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-09-25 18:36:48 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-09-25 18:36:48 -0400
commit262dc6d8cd26a7d4c3be6a01621a98067d92bd57 (patch)
tree2c37b48c95d29f1c2d587b21e790b1f6845f837b
parentfca5a406019e262d6042b325a675646c35492428 (diff)
ease up on artist task concurrency
-rw-r--r--MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs58
1 files changed, 17 insertions, 41 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs
index 73909de27..7c964eacb 100644
--- a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs
+++ b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs
@@ -185,7 +185,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task{Artist[]}.</returns>
- private async Task<ConcurrentBag<Artist>> GetAllArtists(IEnumerable<Audio> allSongs, CancellationToken cancellationToken, IProgress<double> progress)
+ private async Task<List<Artist>> GetAllArtists(IEnumerable<Audio> allSongs, CancellationToken cancellationToken, IProgress<double> progress)
{
var allArtists = allSongs
.SelectMany(i =>
@@ -203,60 +203,36 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
- const int maxTasks = 3;
-
- var tasks = new List<Task>();
-
- var returnArtists = new ConcurrentBag<Artist>();
+ var returnArtists = new List<Artist>(allArtists.Count);
var numComplete = 0;
var numArtists = allArtists.Count;
foreach (var artist in allArtists)
{
- if (tasks.Count > maxTasks)
- {
- await Task.WhenAll(tasks).ConfigureAwait(false);
- tasks.Clear();
-
- // Safe cancellation point, when there are no pending tasks
- cancellationToken.ThrowIfCancellationRequested();
- }
-
- // Avoid accessing the foreach variable within the closure
- var currentArtist = artist;
+ cancellationToken.ThrowIfCancellationRequested();
- tasks.Add(Task.Run(async () =>
+ try
{
- cancellationToken.ThrowIfCancellationRequested();
-
- try
- {
- var artistItem = _libraryManager.GetArtist(currentArtist);
+ var artistItem = _libraryManager.GetArtist(artist);
- await artistItem.RefreshMetadata(cancellationToken).ConfigureAwait(false);
+ await artistItem.RefreshMetadata(cancellationToken).ConfigureAwait(false);
- returnArtists.Add(artistItem);
- }
- catch (IOException ex)
- {
- _logger.ErrorException("Error validating Artist {0}", ex, currentArtist);
- }
+ returnArtists.Add(artistItem);
+ }
+ catch (IOException ex)
+ {
+ _logger.ErrorException("Error validating Artist {0}", ex, artist);
+ }
- // Update progress
- lock (progress)
- {
- numComplete++;
- double percent = numComplete;
- percent /= numArtists;
+ // Update progress
+ numComplete++;
+ double percent = numComplete;
+ percent /= numArtists;
- progress.Report(100 * percent);
- }
- }));
+ progress.Report(100 * percent);
}
- await Task.WhenAll(tasks).ConfigureAwait(false);
-
return returnArtists;
}