diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-03-09 18:14:44 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-03-09 18:14:44 -0400 |
| commit | d49494476770b3c0a091841bd3bbd44862fb8137 (patch) | |
| tree | f0bf4bffa8b4d8a91de9e9096941aa34082a8e91 /MediaBrowser.Server.Implementations/Dto | |
| parent | 1ead63b0d1a532cf828a4ed7c5310eef9c255740 (diff) | |
calculate item by name counts on the fly
Diffstat (limited to 'MediaBrowser.Server.Implementations/Dto')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Dto/DtoService.cs | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 7bf87875e..641bf0a6a 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; } - /// <summary> - /// Attaches the item by name counts. - /// </summary> - /// <param name="dto">The dto.</param> - /// <param name="item">The item.</param> - /// <param name="user">The user.</param> - private void AttachItemByNameCounts(BaseItemDto dto, IItemByName item, User user) + public BaseItemDto GetItemByNameDto<T>(T item, List<ItemFields> 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>(T item, List<ItemFields> fields, List<BaseItem> 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; } /// <summary> |
