diff options
Diffstat (limited to 'MediaBrowser.Controller/Dto/DtoBuilder.cs')
| -rw-r--r-- | MediaBrowser.Controller/Dto/DtoBuilder.cs | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/MediaBrowser.Controller/Dto/DtoBuilder.cs b/MediaBrowser.Controller/Dto/DtoBuilder.cs index 0c47013bf..84f9f8827 100644 --- a/MediaBrowser.Controller/Dto/DtoBuilder.cs +++ b/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); } } |
