From 740a10a4e3f85ffcfd26ec18263d4c78d4b14ecc Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 10 Sep 2013 14:56:00 -0400 Subject: de-normalize item by name data. create counts during library scan for fast access. --- .../Dto/DtoService.cs | 56 ++++++++++++++++++---- 1 file changed, 48 insertions(+), 8 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Dto') diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 46dfd0ba3..5f383f1a0 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -107,6 +107,15 @@ namespace MediaBrowser.Server.Implementations.Dto .ToArray(); } + if (fields.Contains(ItemFields.ItemCounts)) + { + var itemByName = item as IItemByName; + if (itemByName != null) + { + AttachItemByNameCounts(dto, itemByName, user); + } + } + // Make sure all the tasks we kicked off have completed. if (tasks.Count > 0) { @@ -116,6 +125,41 @@ namespace MediaBrowser.Server.Implementations.Dto return dto; } + /// + /// Attaches the item by name counts. + /// + /// The dto. + /// The item. + /// The user. + private void AttachItemByNameCounts(BaseItemDto dto, IItemByName item, User user) + { + ItemByNameCounts counts; + + if (user == null) + { + counts = item.ItemCounts; + } + else + { + if (!item.UserItemCounts.TryGetValue(user.Id, out counts)) + { + counts = new ItemByNameCounts(); + } + } + + dto.ChildCount = counts.TotalCount; + + dto.AdultVideoCount = counts.AdultVideoCount; + dto.AlbumCount = counts.AlbumCount; + dto.EpisodeCount = counts.EpisodeCount; + dto.GameCount = counts.GameCount; + dto.MovieCount = counts.MovieCount; + dto.MusicVideoCount = counts.MusicVideoCount; + dto.SeriesCount = counts.SeriesCount; + dto.SongCount = counts.SongCount; + dto.TrailerCount = counts.TrailerCount; + } + /// /// Attaches the user specific info. /// @@ -380,7 +424,9 @@ namespace MediaBrowser.Server.Implementations.Dto _logger.ErrorException("Error getting {0} image info for {1}", ex, type, path); return null; } - } /// + } + + /// /// Attaches People DTO's to a DTOBaseItem /// /// The dto. @@ -913,12 +959,7 @@ namespace MediaBrowser.Server.Implementations.Dto if (album != null) { - var songs = album.RecursiveChildren.OfType