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 +++- .../HttpServer/NativeWebSocket.cs | 4 + .../Library/LibraryManager.cs | 219 +++++++++------- .../Library/LuceneSearchEngine.cs | 4 +- .../Library/Validators/ArtistsPostScanTask.cs | 38 +++ .../Library/Validators/ArtistsValidator.cs | 285 +++++++++++++++++++++ .../Library/Validators/CountHelpers.cs | 155 +++++++++++ .../Library/Validators/GameGenresPostScanTask.cs | 45 ++++ .../Library/Validators/GameGenresValidator.cs | 132 ++++++++++ .../Library/Validators/GenresPostScanTask.cs | 42 +++ .../Library/Validators/GenresValidator.cs | 135 ++++++++++ .../Library/Validators/MusicGenresPostScanTask.cs | 45 ++++ .../Library/Validators/MusicGenresValidator.cs | 135 ++++++++++ .../Library/Validators/PeoplePostScanTask.cs | 137 ++++++++++ .../Library/Validators/StudiosPostScanTask.cs | 45 ++++ .../Library/Validators/StudiosValidator.cs | 132 ++++++++++ .../MediaBrowser.Server.Implementations.csproj | 13 +- .../Providers/ProviderManager.cs | 6 +- .../ScheduledTasks/ArtistValidationTask.cs | 81 ------ .../Session/SessionManager.cs | 6 +- 20 files changed, 1527 insertions(+), 188 deletions(-) create mode 100644 MediaBrowser.Server.Implementations/Library/Validators/ArtistsPostScanTask.cs create mode 100644 MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs create mode 100644 MediaBrowser.Server.Implementations/Library/Validators/CountHelpers.cs create mode 100644 MediaBrowser.Server.Implementations/Library/Validators/GameGenresPostScanTask.cs create mode 100644 MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs create mode 100644 MediaBrowser.Server.Implementations/Library/Validators/GenresPostScanTask.cs create mode 100644 MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs create mode 100644 MediaBrowser.Server.Implementations/Library/Validators/MusicGenresPostScanTask.cs create mode 100644 MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs create mode 100644 MediaBrowser.Server.Implementations/Library/Validators/PeoplePostScanTask.cs create mode 100644 MediaBrowser.Server.Implementations/Library/Validators/StudiosPostScanTask.cs create mode 100644 MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs delete mode 100644 MediaBrowser.Server.Implementations/ScheduledTasks/ArtistValidationTask.cs (limited to 'MediaBrowser.Server.Implementations') 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