more task reduction

This commit is contained in:
Luke Pulverenti 2013-04-15 16:33:43 -04:00
parent 9279893434
commit 0fc6158500
12 changed files with 83 additions and 86 deletions

View file

@ -54,7 +54,6 @@ namespace MediaBrowser.Controller.Providers
CheckCharacters = false, CheckCharacters = false,
IgnoreProcessingInstructions = true, IgnoreProcessingInstructions = true,
IgnoreComments = true, IgnoreComments = true,
IgnoreWhitespace = true,
ValidationType = ValidationType.None ValidationType = ValidationType.None
}; };

View file

@ -31,6 +31,12 @@ namespace MediaBrowser.Controller.Providers
/// </summary> /// </summary>
protected readonly Guid Id; protected readonly Guid Id;
/// <summary>
/// The true task result
/// </summary>
protected static readonly Task<bool> TrueTaskResult = Task.FromResult(true);
protected static readonly Task<bool> FalseTaskResult = Task.FromResult(false);
protected static readonly SemaphoreSlim XmlParsingResourcePool = new SemaphoreSlim(5, 5); protected static readonly SemaphoreSlim XmlParsingResourcePool = new SemaphoreSlim(5, 5);
/// <summary> /// <summary>
@ -207,7 +213,7 @@ namespace MediaBrowser.Controller.Providers
return true; return true;
} }
if (RefreshOnVersionChange && !string.Equals(ProviderVersion, providerInfo.ProviderVersion)) if (RefreshOnVersionChange && !String.Equals(ProviderVersion, providerInfo.ProviderVersion))
{ {
return true; return true;
} }
@ -223,7 +229,7 @@ namespace MediaBrowser.Controller.Providers
/// <returns><c>true</c> if [has file system stamp changed] [the specified item]; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if [has file system stamp changed] [the specified item]; otherwise, <c>false</c>.</returns>
protected bool HasFileSystemStampChanged(BaseItem item, BaseProviderInfo providerInfo) protected bool HasFileSystemStampChanged(BaseItem item, BaseProviderInfo providerInfo)
{ {
return !string.Equals(GetCurrentFileSystemStamp(item), providerInfo.FileSystemStamp); return !String.Equals(GetCurrentFileSystemStamp(item), providerInfo.FileSystemStamp);
} }
/// <summary> /// <summary>

View file

@ -52,11 +52,6 @@ namespace MediaBrowser.Controller.Providers
} }
} }
/// <summary>
/// The true task result
/// </summary>
protected static readonly Task<bool> TrueTaskResult = Task.FromResult(true);
/// <summary> /// <summary>
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done /// Fetches metadata and returns true or false indicating if any work that requires persistence was done
/// </summary> /// </summary>

View file

@ -80,9 +80,6 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns> /// <returns>Task{System.Boolean}.</returns>
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken) public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
// Since we don't have anything truly async, and since deserializing can be expensive, create a task to force parallelism
return Task.Run(() =>
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@ -97,10 +94,9 @@ namespace MediaBrowser.Controller.Providers.Movies
ProcessMainInfo(item, movieData); ProcessMainInfo(item, movieData);
SetLastRefreshed(item, DateTime.UtcNow); SetLastRefreshed(item, DateTime.UtcNow);
return true; return TrueTaskResult;
} }
return false; return FalseTaskResult;
});
} }
} }
} }

View file

@ -91,8 +91,6 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns> /// <returns>Task{System.Boolean}.</returns>
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken) public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
return Task.Run(() =>
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@ -105,15 +103,13 @@ namespace MediaBrowser.Controller.Providers.Movies
ProcessInfo((Person)item, personInfo); ProcessInfo((Person)item, personInfo);
SetLastRefreshed(item, DateTime.UtcNow); SetLastRefreshed(item, DateTime.UtcNow);
return true; return TrueTaskResult;
} }
catch (FileNotFoundException) catch (FileNotFoundException)
{ {
// This is okay - just means we force refreshed and there isn't a json file // This is okay - just means we force refreshed and there isn't a json file
return false; return FalseTaskResult;
} }
});
} }
} }
} }

View file

@ -31,8 +31,6 @@ namespace MediaBrowser.Controller.Providers.Music
} }
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken) public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
return Task.Run(() =>
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@ -49,10 +47,9 @@ namespace MediaBrowser.Controller.Providers.Music
item.SetProviderId(MetadataProviders.Musicbrainz, data.mbid); item.SetProviderId(MetadataProviders.Musicbrainz, data.mbid);
SetLastRefreshed(item, DateTime.UtcNow); SetLastRefreshed(item, DateTime.UtcNow);
return true; return TrueTaskResult;
} }
return false; return FalseTaskResult;
});
} }
public override MetadataProviderPriority Priority public override MetadataProviderPriority Priority

View file

@ -3,6 +3,7 @@ using MediaBrowser.Common.MediaInfo;
using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers.MediaInfo; using MediaBrowser.Controller.Providers.MediaInfo;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
@ -95,9 +96,17 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
/// <returns>Task.</returns> /// <returns>Task.</returns>
public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress) public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
{ {
var items = _libraryManager.RootFolder.RecursiveChildren var allItems = _libraryManager.RootFolder.RecursiveChildren.ToList();
.OfType<Video>()
.Where(i => var localTrailers = allItems.SelectMany(i => i.LocalTrailers);
var videos = allItems.OfType<Video>().ToList();
var items = videos;
items.AddRange(localTrailers);
items.AddRange(videos.OfType<Movie>().SelectMany(i => i.SpecialFeatures).ToList());
items = items.Where(i =>
{ {
if (!string.IsNullOrEmpty(i.PrimaryImagePath)) if (!string.IsNullOrEmpty(i.PrimaryImagePath))
{ {
@ -120,8 +129,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
} }
return i.MediaStreams != null && i.MediaStreams.Any(m => m.Type == MediaStreamType.Video); return i.MediaStreams != null && i.MediaStreams.Any(m => m.Type == MediaStreamType.Video);
}) }).ToList();
.ToList();
progress.Report(0); progress.Report(0);

View file

@ -86,7 +86,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
{ {
var dbFile = Path.Combine(_appPaths.DataPath, "displaypreferences.db"); var dbFile = Path.Combine(_appPaths.DataPath, "displaypreferences.db");
await ConnectToDB(dbFile).ConfigureAwait(false); await ConnectToDb(dbFile).ConfigureAwait(false);
string[] queries = { string[] queries = {

View file

@ -82,7 +82,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
{ {
var dbFile = Path.Combine(_appPaths.DataPath, "library.db"); var dbFile = Path.Combine(_appPaths.DataPath, "library.db");
await ConnectToDB(dbFile).ConfigureAwait(false); await ConnectToDb(dbFile).ConfigureAwait(false);
string[] queries = { string[] queries = {

View file

@ -76,7 +76,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
/// <param name="dbPath">The db path.</param> /// <param name="dbPath">The db path.</param>
/// <returns>Task{System.Boolean}.</returns> /// <returns>Task{System.Boolean}.</returns>
/// <exception cref="System.ArgumentNullException">dbPath</exception> /// <exception cref="System.ArgumentNullException">dbPath</exception>
protected async Task ConnectToDB(string dbPath) protected async Task ConnectToDb(string dbPath)
{ {
if (string.IsNullOrEmpty(dbPath)) if (string.IsNullOrEmpty(dbPath))
{ {

View file

@ -86,7 +86,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
{ {
var dbFile = Path.Combine(_appPaths.DataPath, "userdata.db"); var dbFile = Path.Combine(_appPaths.DataPath, "userdata.db");
await ConnectToDB(dbFile).ConfigureAwait(false); await ConnectToDb(dbFile).ConfigureAwait(false);
string[] queries = { string[] queries = {

View file

@ -88,7 +88,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
{ {
var dbFile = Path.Combine(_appPaths.DataPath, "users.db"); var dbFile = Path.Combine(_appPaths.DataPath, "users.db");
await ConnectToDB(dbFile).ConfigureAwait(false); await ConnectToDb(dbFile).ConfigureAwait(false);
string[] queries = { string[] queries = {