fixed people images being occasionally incorrect

This commit is contained in:
Luke Pulverenti 2013-04-14 16:47:09 -04:00
parent bc833492f0
commit 95b1bfb0de
3 changed files with 16 additions and 12 deletions

View File

@ -293,7 +293,7 @@ namespace MediaBrowser.Api.Images
if (string.IsNullOrEmpty(imagePath)) if (string.IsNullOrEmpty(imagePath))
{ {
throw new ResourceNotFoundException(); throw new ResourceNotFoundException(string.Format("{0} does not have an image of type {1}", item.Name, request.Type));
} }
// See if we can avoid a file system lookup by looking for the file in ResolveArgs // See if we can avoid a file system lookup by looking for the file in ResolveArgs

View File

@ -566,29 +566,33 @@ namespace MediaBrowser.Controller.Dto
return; return;
} }
// Attach People by transforming them into BaseItemPerson (DTO)
dto.People = new BaseItemPerson[item.People.Count];
// Ordering by person type to ensure actors and artists are at the front. // Ordering by person type to ensure actors and artists are at the front.
// This is taking advantage of the fact that they both begin with A // This is taking advantage of the fact that they both begin with A
// This should be improved in the future // This should be improved in the future
var entities = await Task.WhenAll(item.People.OrderBy(i => i.Type).Select(c => var people = item.People.OrderBy(i => i.Type).ToList();
// Attach People by transforming them into BaseItemPerson (DTO)
dto.People = new BaseItemPerson[people.Count];
var entities = await Task.WhenAll(people.Select(p => p.Name).Distinct(StringComparer.OrdinalIgnoreCase).Select(c =>
Task.Run(async () => Task.Run(async () =>
{ {
try try
{ {
return await _libraryManager.GetPerson(c.Name).ConfigureAwait(false); return await _libraryManager.GetPerson(c).ConfigureAwait(false);
} }
catch (IOException ex) catch (IOException ex)
{ {
_logger.ErrorException("Error getting person {0}", ex, c.Name); _logger.ErrorException("Error getting person {0}", ex, c);
return null; return null;
} }
}) })
)).ConfigureAwait(false); )).ConfigureAwait(false);
var dictionary = entities.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
for (var i = 0; i < item.People.Count; i++) for (var i = 0; i < item.People.Count; i++)
{ {
var person = item.People[i]; var person = item.People[i];
@ -600,15 +604,15 @@ namespace MediaBrowser.Controller.Dto
Type = person.Type Type = person.Type
}; };
var ibnObject = entities[i]; Person entity;
if (ibnObject != null) if (dictionary.TryGetValue(person.Name, out entity))
{ {
var primaryImagePath = ibnObject.PrimaryImagePath; var primaryImagePath = entity.PrimaryImagePath;
if (!string.IsNullOrEmpty(primaryImagePath)) if (!string.IsNullOrEmpty(primaryImagePath))
{ {
baseItemPerson.PrimaryImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(ibnObject, ImageType.Primary, primaryImagePath); baseItemPerson.PrimaryImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(entity, ImageType.Primary, primaryImagePath);
} }
} }

View File

@ -237,7 +237,7 @@ namespace MediaBrowser.Server.Implementations.Providers
} }
catch (OperationCanceledException ex) catch (OperationCanceledException ex)
{ {
_logger.Debug("{0} cancelled for {1}", provider.GetType().Name, item.Name); _logger.Debug("{0} canceled for {1}", provider.GetType().Name, item.Name);
// If the outer cancellation token is the one that caused the cancellation, throw it // If the outer cancellation token is the one that caused the cancellation, throw it
if (cancellationToken.IsCancellationRequested && ex.CancellationToken == cancellationToken) if (cancellationToken.IsCancellationRequested && ex.CancellationToken == cancellationToken)