From 63fe0239e35caec6aba1c5e65581d2d1e7a4e4bd Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Mar 2016 20:15:56 -0400 Subject: update album queries --- MediaBrowser.Controller/Entities/InternalItemsQuery.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'MediaBrowser.Controller/Entities/InternalItemsQuery.cs') diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index 2f98ac70d..da76e7db0 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -125,7 +125,8 @@ namespace MediaBrowser.Controller.Entities public DayOfWeek[] AirDays { get; set; } public SeriesStatus[] SeriesStatuses { get; set; } - + public string AlbumArtistStartsWithOrGreater { get; set; } + public InternalItemsQuery() { BlockUnratedItems = new UnratedItem[] { }; -- cgit v1.2.3 From d4870e788ac7f65190f6c82ec766d0340533de8c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Mar 2016 23:10:37 -0400 Subject: update db querying --- MediaBrowser.Api/Reports/ReportsService.cs | 73 ++++------------------ MediaBrowser.Api/UserLibrary/ItemsService.cs | 64 ++++--------------- MediaBrowser.Controller/Entities/Folder.cs | 6 -- .../Entities/InternalItemsQuery.cs | 1 + .../Persistence/SqliteItemRepository.cs | 6 ++ 5 files changed, 31 insertions(+), 119 deletions(-) (limited to 'MediaBrowser.Controller/Entities/InternalItemsQuery.cs') diff --git a/MediaBrowser.Api/Reports/ReportsService.cs b/MediaBrowser.Api/Reports/ReportsService.cs index 5b492d8b4..5dc6e2d84 100644 --- a/MediaBrowser.Api/Reports/ReportsService.cs +++ b/MediaBrowser.Api/Reports/ReportsService.cs @@ -338,6 +338,18 @@ namespace MediaBrowser.Api.Reports query.LocationTypes = request.LocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray(); } + // Min official rating + if (!string.IsNullOrEmpty(request.MinOfficialRating)) + { + query.MinParentalRating = _localization.GetRatingLevel(request.MinOfficialRating); + } + + // Max official rating + if (!string.IsNullOrEmpty(request.MaxOfficialRating)) + { + query.MaxParentalRating = _localization.GetRatingLevel(request.MinOfficialRating); + } + if (request.HasQueryLimit == false) { query.StartIndex = null; @@ -417,67 +429,6 @@ namespace MediaBrowser.Api.Reports return false; } - // Min index number - if (request.MinIndexNumber.HasValue) - { - if (!(i.IndexNumber.HasValue && i.IndexNumber.Value >= request.MinIndexNumber.Value)) - { - return false; - } - } - - // Min official rating - if (!string.IsNullOrEmpty(request.MinOfficialRating)) - { - var level = _localization.GetRatingLevel(request.MinOfficialRating); - - if (level.HasValue) - { - var rating = i.CustomRating; - - if (string.IsNullOrEmpty(rating)) - { - rating = i.OfficialRating; - } - - if (!string.IsNullOrEmpty(rating)) - { - var itemLevel = _localization.GetRatingLevel(rating); - - if (!(!itemLevel.HasValue || itemLevel.Value >= level.Value)) - { - return false; - } - } - } - } - - // Max official rating - if (!string.IsNullOrEmpty(request.MaxOfficialRating)) - { - var level = _localization.GetRatingLevel(request.MaxOfficialRating); - - if (level.HasValue) - { - var rating = i.CustomRating; - - if (string.IsNullOrEmpty(rating)) - { - rating = i.OfficialRating; - } - - if (!string.IsNullOrEmpty(rating)) - { - var itemLevel = _localization.GetRatingLevel(rating); - - if (!(!itemLevel.HasValue || itemLevel.Value <= level.Value)) - { - return false; - } - } - } - } - return true; } diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 92b2d6002..f32165fca 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -310,6 +310,18 @@ namespace MediaBrowser.Api.UserLibrary { query.LocationTypes = request.LocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray(); } + + // Min official rating + if (!string.IsNullOrEmpty(request.MinOfficialRating)) + { + query.MinParentalRating = _localization.GetRatingLevel(request.MinOfficialRating); + } + + // Max official rating + if (!string.IsNullOrEmpty(request.MaxOfficialRating)) + { + query.MaxParentalRating = _localization.GetRatingLevel(request.MinOfficialRating); + } return query; } @@ -384,58 +396,6 @@ namespace MediaBrowser.Api.UserLibrary return false; } - // Min official rating - if (!string.IsNullOrEmpty(request.MinOfficialRating)) - { - var level = _localization.GetRatingLevel(request.MinOfficialRating); - - if (level.HasValue) - { - var rating = i.CustomRating; - - if (string.IsNullOrEmpty(rating)) - { - rating = i.OfficialRating; - } - - if (!string.IsNullOrEmpty(rating)) - { - var itemLevel = _localization.GetRatingLevel(rating); - - if (!(!itemLevel.HasValue || itemLevel.Value >= level.Value)) - { - return false; - } - } - } - } - - // Max official rating - if (!string.IsNullOrEmpty(request.MaxOfficialRating)) - { - var level = _localization.GetRatingLevel(request.MaxOfficialRating); - - if (level.HasValue) - { - var rating = i.CustomRating; - - if (string.IsNullOrEmpty(rating)) - { - rating = i.OfficialRating; - } - - if (!string.IsNullOrEmpty(rating)) - { - var itemLevel = _localization.GetRatingLevel(rating); - - if (!(!itemLevel.HasValue || itemLevel.Value <= level.Value)) - { - return false; - } - } - } - } - return true; } } diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 7314f81c7..d2fa5d9a0 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -1091,12 +1091,6 @@ namespace MediaBrowser.Controller.Entities return true; } - if (query.MinIndexNumber.HasValue) - { - Logger.Debug("Query requires post-filtering due to MinIndexNumber"); - return true; - } - if (query.OfficialRatings.Length > 0) { Logger.Debug("Query requires post-filtering due to OfficialRatings"); diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index da76e7db0..e98c89abf 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -105,6 +105,7 @@ namespace MediaBrowser.Controller.Entities internal List ItemIdsFromPersonFilters { get; set; } public int? ParentIndexNumber { get; set; } + public int? MinParentalRating { get; set; } public int? MaxParentalRating { get; set; } public bool? IsCurrentSchema { get; set; } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 1ec74a39d..a6e92171f 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -2062,6 +2062,12 @@ namespace MediaBrowser.Server.Implementations.Persistence whereClauses.Add(clause); } + if (query.MinParentalRating.HasValue) + { + whereClauses.Add("InheritedParentalRatingValue<=@MinParentalRating"); + cmd.Parameters.Add(cmd, "@MinParentalRating", DbType.Int32).Value = query.MinParentalRating.Value; + } + if (query.MaxParentalRating.HasValue) { whereClauses.Add("InheritedParentalRatingValue<=@MaxParentalRating"); -- cgit v1.2.3 From 23fe6dc4be28c4d273bb22962ac769c749931090 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 21 Mar 2016 12:50:50 -0400 Subject: update db querying --- MediaBrowser.Api/Reports/ReportsService.cs | 63 +++++----------------- MediaBrowser.Api/UserLibrary/ItemsService.cs | 63 +++++----------------- MediaBrowser.Controller/Entities/Folder.cs | 12 +++++ .../Entities/InternalItemsQuery.cs | 6 +++ .../Entities/UserViewBuilder.cs | 47 ++++++++++++++++ 5 files changed, 89 insertions(+), 102 deletions(-) (limited to 'MediaBrowser.Controller/Entities/InternalItemsQuery.cs') diff --git a/MediaBrowser.Api/Reports/ReportsService.cs b/MediaBrowser.Api/Reports/ReportsService.cs index 5dc6e2d84..15bdf4be6 100644 --- a/MediaBrowser.Api/Reports/ReportsService.cs +++ b/MediaBrowser.Api/Reports/ReportsService.cs @@ -350,6 +350,18 @@ namespace MediaBrowser.Api.Reports query.MaxParentalRating = _localization.GetRatingLevel(request.MinOfficialRating); } + // Artists + if (!string.IsNullOrEmpty(request.Artists)) + { + query.ArtistNames = request.Artists.Split('|'); + } + + // Albums + if (!string.IsNullOrEmpty(request.Albums)) + { + query.AlbumNames = request.Albums.Split('|'); + } + if (request.HasQueryLimit == false) { query.StartIndex = null; @@ -378,57 +390,6 @@ namespace MediaBrowser.Api.Reports } } - // Artists - if (!string.IsNullOrEmpty(request.Artists)) - { - var artists = request.Artists.Split('|'); - - var audio = i as IHasArtist; - - if (!(audio != null && artists.Any(audio.HasAnyArtist))) - { - return false; - } - } - - // Albums - if (!string.IsNullOrEmpty(request.Albums)) - { - var albums = request.Albums.Split('|'); - - var audio = i as Audio; - - if (audio != null) - { - if (!albums.Any(a => string.Equals(a, audio.Album, StringComparison.OrdinalIgnoreCase))) - { - return false; - } - } - - var album = i as MusicAlbum; - - if (album != null) - { - if (!albums.Any(a => string.Equals(a, album.Name, StringComparison.OrdinalIgnoreCase))) - { - return false; - } - } - - var musicVideo = i as MusicVideo; - - if (musicVideo != null) - { - if (!albums.Any(a => string.Equals(a, musicVideo.Album, StringComparison.OrdinalIgnoreCase))) - { - return false; - } - } - - return false; - } - return true; } diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index f32165fca..566b1dfd5 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -323,6 +323,18 @@ namespace MediaBrowser.Api.UserLibrary query.MaxParentalRating = _localization.GetRatingLevel(request.MinOfficialRating); } + // Artists + if (!string.IsNullOrEmpty(request.Artists)) + { + query.ArtistNames = request.Artists.Split('|'); + } + + // Albums + if (!string.IsNullOrEmpty(request.Albums)) + { + query.AlbumNames = request.Albums.Split('|'); + } + return query; } @@ -345,57 +357,6 @@ namespace MediaBrowser.Api.UserLibrary } } - // Artists - if (!string.IsNullOrEmpty(request.Artists)) - { - var artists = request.Artists.Split('|'); - - var audio = i as IHasArtist; - - if (!(audio != null && artists.Any(audio.HasAnyArtist))) - { - return false; - } - } - - // Albums - if (!string.IsNullOrEmpty(request.Albums)) - { - var albums = request.Albums.Split('|'); - - var audio = i as Audio; - - if (audio != null) - { - if (!albums.Any(a => string.Equals(a, audio.Album, StringComparison.OrdinalIgnoreCase))) - { - return false; - } - } - - var album = i as MusicAlbum; - - if (album != null) - { - if (!albums.Any(a => string.Equals(a, album.Name, StringComparison.OrdinalIgnoreCase))) - { - return false; - } - } - - var musicVideo = i as MusicVideo; - - if (musicVideo != null) - { - if (!albums.Any(a => string.Equals(a, musicVideo.Album, StringComparison.OrdinalIgnoreCase))) - { - return false; - } - } - - return false; - } - return true; } } diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index d2fa5d9a0..fa96ba4e5 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -1175,6 +1175,18 @@ namespace MediaBrowser.Controller.Entities return true; } + if (query.AlbumNames.Length > 0) + { + Logger.Debug("Query requires post-filtering due to AlbumNames"); + return true; + } + + if (query.ArtistNames.Length > 0) + { + Logger.Debug("Query requires post-filtering due to ArtistNames"); + return true; + } + return false; } diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index e98c89abf..b568aec18 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -128,8 +128,14 @@ namespace MediaBrowser.Controller.Entities public SeriesStatus[] SeriesStatuses { get; set; } public string AlbumArtistStartsWithOrGreater { get; set; } + public string[] AlbumNames { get; set; } + public string[] ArtistNames { get; set; } + public InternalItemsQuery() { + AlbumNames = new string[] { }; + ArtistNames = new string[] { }; + BlockUnratedItems = new UnratedItem[] { }; Tags = new string[] { }; OfficialRatings = new string[] { }; diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index ee5412d62..a74859a46 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -1768,6 +1768,53 @@ namespace MediaBrowser.Controller.Entities } } + // Artists + if (query.ArtistNames.Length > 0) + { + var audio = item as IHasArtist; + + if (!(audio != null && query.ArtistNames.Any(audio.HasAnyArtist))) + { + return false; + } + } + + // Albums + if (query.AlbumNames.Length > 0) + { + var audio = item as Audio.Audio; + + if (audio != null) + { + if (!query.AlbumNames.Any(a => string.Equals(a, audio.Album, StringComparison.OrdinalIgnoreCase))) + { + return false; + } + } + + var album = item as MusicAlbum; + + if (album != null) + { + if (!query.AlbumNames.Any(a => string.Equals(a, album.Name, StringComparison.OrdinalIgnoreCase))) + { + return false; + } + } + + var musicVideo = item as MusicVideo; + + if (musicVideo != null) + { + if (!query.AlbumNames.Any(a => string.Equals(a, musicVideo.Album, StringComparison.OrdinalIgnoreCase))) + { + return false; + } + } + + return false; + } + return true; } -- cgit v1.2.3