reduce recursive querying

This commit is contained in:
Luke Pulverenti
2016-05-06 00:50:39 -04:00
parent 242fb3c770
commit 5a496a1fc8
10 changed files with 263 additions and 289 deletions

View File

@@ -2,7 +2,6 @@
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -35,25 +34,20 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
/// <returns>Task.</returns>
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
var items = _libraryManager.RootFolder.GetRecursiveChildren()
.SelectMany(i => i.Studios)
.DistinctNames()
.ToList();
var items = _libraryManager.GetItemList(new InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(Studio).Name }
}).ToList();
var numComplete = 0;
var count = items.Count;
var validIds = new List<Guid>();
foreach (var name in items)
foreach (var item in items)
{
try
{
var itemByName = _libraryManager.GetStudio(name);
validIds.Add(itemByName.Id);
await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false);
await item.RefreshMetadata(cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
@@ -62,7 +56,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
}
catch (Exception ex)
{
_logger.ErrorException("Error refreshing {0}", ex, name);
_logger.ErrorException("Error refreshing {0}", ex, item.Name);
}
numComplete++;
@@ -73,28 +67,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
progress.Report(percent);
}
var allIds = _libraryManager.GetItemIds(new InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(Studio).Name }
});
var invalidIds = allIds
.Except(validIds)
.ToList();
foreach (var id in invalidIds)
{
cancellationToken.ThrowIfCancellationRequested();
var item = _libraryManager.GetItemById(id);
await _libraryManager.DeleteItem(item, new DeleteOptions
{
DeleteFileLocation = false
}).ConfigureAwait(false);
}
progress.Report(100);
}
}