瀏覽代碼

fixed people images being occasionally incorrect

Luke Pulverenti 12 年之前
父節點
當前提交
95b1bfb0de

+ 1 - 1
MediaBrowser.Api/Images/ImageService.cs

@@ -293,7 +293,7 @@ namespace MediaBrowser.Api.Images
 
             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

+ 14 - 10
MediaBrowser.Controller/Dto/DtoBuilder.cs

@@ -566,29 +566,33 @@ namespace MediaBrowser.Controller.Dto
                 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.
             // This is taking advantage of the fact that they both begin with A
             // 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 () =>
                     {
                         try
                         {
-                            return await _libraryManager.GetPerson(c.Name).ConfigureAwait(false);
+                            return await _libraryManager.GetPerson(c).ConfigureAwait(false);
                         }
                         catch (IOException ex)
                         {
-                            _logger.ErrorException("Error getting person {0}", ex, c.Name);
+                            _logger.ErrorException("Error getting person {0}", ex, c);
                             return null;
                         }
                     })
 
             )).ConfigureAwait(false);
 
+            var dictionary = entities.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
+
             for (var i = 0; i < item.People.Count; i++)
             {
                 var person = item.People[i];
@@ -600,15 +604,15 @@ namespace MediaBrowser.Controller.Dto
                     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))
                     {
-                        baseItemPerson.PrimaryImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(ibnObject, ImageType.Primary, primaryImagePath);
+                        baseItemPerson.PrimaryImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(entity, ImageType.Primary, primaryImagePath);
                     }
                 }
 

+ 1 - 1
MediaBrowser.Server.Implementations/Providers/ProviderManager.cs

@@ -237,7 +237,7 @@ namespace MediaBrowser.Server.Implementations.Providers
             }
             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 (cancellationToken.IsCancellationRequested && ex.CancellationToken == cancellationToken)