From d49494476770b3c0a091841bd3bbd44862fb8137 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 9 Mar 2014 18:14:44 -0400 Subject: calculate item by name counts on the fly --- .../Dto/DtoService.cs | 62 +++++++++++++--------- 1 file changed, 36 insertions(+), 26 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Dto') diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 7bf87875ed..641bf0a6a6 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -121,41 +121,51 @@ namespace MediaBrowser.Server.Implementations.Dto } } - var itemByName = item as IItemByName; - if (itemByName != null) - { - AttachItemByNameCounts(dto, itemByName, user); - } - return dto; } - /// - /// Attaches the item by name counts. - /// - /// The dto. - /// The item. - /// The user. - private void AttachItemByNameCounts(BaseItemDto dto, IItemByName item, User user) + public BaseItemDto GetItemByNameDto(T item, List fields, User user = null) + where T : BaseItem, IItemByName { - if (user == null) + var libraryItems = user != null ? user.RootFolder.GetRecursiveChildren(user) : + _libraryManager.RootFolder.RecursiveChildren; + + return GetItemByNameDto(item, fields, item.GetTaggedItems(libraryItems).ToList(), user); + } + + public BaseItemDto GetItemByNameDto(T item, List fields, List taggedItems, User user = null) + where T : BaseItem, IItemByName + { + var dto = GetBaseItemDto(item, fields, user); + + if (item is MusicArtist || item is MusicGenre) { - return; + dto.AlbumCount = taggedItems.Count(i => i is MusicAlbum); + dto.MusicVideoCount = taggedItems.Count(i => i is MusicVideo); + dto.SongCount = taggedItems.Count(i => i is Audio); + } + else if (item is GameGenre) + { + dto.GameCount = taggedItems.Count(i => i is Game); } + else + { + // This populates them all and covers Genre, Person, Studio, Year - var counts = item.GetItemByNameCounts(user.Id) ?? new ItemByNameCounts(); + dto.AdultVideoCount = taggedItems.Count(i => i is AdultVideo); + dto.AlbumCount = taggedItems.Count(i => i is MusicAlbum); + dto.EpisodeCount = taggedItems.Count(i => i is Episode); + dto.GameCount = taggedItems.Count(i => i is Game); + dto.MovieCount = taggedItems.Count(i => i is Movie); + dto.MusicVideoCount = taggedItems.Count(i => i is MusicVideo); + dto.SeriesCount = taggedItems.Count(i => i is Series); + dto.SongCount = taggedItems.Count(i => i is Audio); + dto.TrailerCount = taggedItems.Count(i => i is Trailer); + } - dto.ChildCount = counts.TotalCount; + dto.ChildCount = taggedItems.Count; - 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; + return dto; } /// -- cgit v1.2.3