From 2979185d8e658dfa083ac4c29cd982e00ba1933a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 2 Jun 2016 00:41:12 -0400 Subject: [PATCH 1/4] add provider ids to database --- MediaBrowser.Api/Reports/ReportsService.cs | 1 - .../UserLibrary/BaseItemsRequest.cs | 3 - MediaBrowser.Api/UserLibrary/ItemsService.cs | 1 - MediaBrowser.Controller/Entities/BaseItem.cs | 1 + MediaBrowser.Controller/Entities/Folder.cs | 24 ----- .../Entities/InternalItemsQuery.cs | 5 +- .../Entities/UserViewBuilder.cs | 43 --------- ...MediaBrowser.Server.Implementations.csproj | 4 +- .../Persistence/SqliteItemRepository.cs | 89 ++++++++++++++++++- .../packages.config | 2 +- 10 files changed, 95 insertions(+), 78 deletions(-) diff --git a/MediaBrowser.Api/Reports/ReportsService.cs b/MediaBrowser.Api/Reports/ReportsService.cs index cb1615826..36a2a4b61 100644 --- a/MediaBrowser.Api/Reports/ReportsService.cs +++ b/MediaBrowser.Api/Reports/ReportsService.cs @@ -213,7 +213,6 @@ namespace MediaBrowser.Api.Reports NameStartsWith = request.NameStartsWith, NameStartsWithOrGreater = request.NameStartsWithOrGreater, HasImdbId = request.HasImdbId, - IsYearMismatched = request.IsYearMismatched, IsPlaceHolder = request.IsPlaceHolder, IsLocked = request.IsLocked, IsInBoxSet = request.IsInBoxSet, diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs index aee1a8d54..d27a560ba 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs @@ -100,9 +100,6 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "HasTvdbId", Description = "Optional filter by items that have a tvdb id or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] public bool? HasTvdbId { get; set; } - [ApiMember(Name = "IsYearMismatched", Description = "Optional filter by items that are potentially misidentified.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? IsYearMismatched { get; set; } - [ApiMember(Name = "IsInBoxSet", Description = "Optional filter by items that are in boxsets, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] public bool? IsInBoxSet { get; set; } diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index dac1a6b1a..644b28437 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -187,7 +187,6 @@ namespace MediaBrowser.Api.UserLibrary NameStartsWith = request.NameStartsWith, NameStartsWithOrGreater = request.NameStartsWithOrGreater, HasImdbId = request.HasImdbId, - IsYearMismatched = request.IsYearMismatched, IsPlaceHolder = request.IsPlaceHolder, IsLocked = request.IsLocked, IsInBoxSet = request.IsInBoxSet, diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 78f1828ea..5101a9f28 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -75,6 +75,7 @@ namespace MediaBrowser.Controller.Entities /// Gets or sets the album. /// /// The album. + [IgnoreDataMember] public string Album { get; set; } /// diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 0d307c35b..a4cbd34b2 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -840,30 +840,6 @@ namespace MediaBrowser.Controller.Entities return true; } - if (query.HasImdbId.HasValue) - { - Logger.Debug("Query requires post-filtering due to HasImdbId"); - return true; - } - - if (query.HasTmdbId.HasValue) - { - Logger.Debug("Query requires post-filtering due to HasTmdbId"); - return true; - } - - if (query.HasTvdbId.HasValue) - { - Logger.Debug("Query requires post-filtering due to HasTvdbId"); - return true; - } - - if (query.IsYearMismatched.HasValue) - { - Logger.Debug("Query requires post-filtering due to IsYearMismatched"); - return true; - } - if (query.HasOfficialRating.HasValue) { Logger.Debug("Query requires post-filtering due to HasOfficialRating"); diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index 0047a13b2..04dfc9491 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -64,7 +64,6 @@ namespace MediaBrowser.Controller.Entities public bool? IsInBoxSet { get; set; } public bool? IsLocked { get; set; } public bool? IsPlaceHolder { get; set; } - public bool? IsYearMismatched { get; set; } public bool? HasImdbId { get; set; } public bool? HasOverview { get; set; } @@ -141,6 +140,7 @@ namespace MediaBrowser.Controller.Entities public bool GroupByPresentationUniqueKey { get; set; } public bool EnableTotalRecordCount { get; set; } public bool ForceDirect { get; set; } + public Dictionary ExcludeProviderIds { get; set; } public InternalItemsQuery() { @@ -149,7 +149,8 @@ namespace MediaBrowser.Controller.Entities AlbumNames = new string[] { }; ArtistNames = new string[] { }; - + ExcludeProviderIds = new Dictionary(StringComparer.OrdinalIgnoreCase); + BlockUnratedItems = new UnratedItem[] { }; Tags = new string[] { }; OfficialRatings = new string[] { }; diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 2bde80641..655dff06a 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -995,11 +995,6 @@ namespace MediaBrowser.Controller.Entities return false; } - if (request.IsYearMismatched.HasValue) - { - return false; - } - if (!string.IsNullOrWhiteSpace(request.Person)) { return false; @@ -1418,16 +1413,6 @@ namespace MediaBrowser.Controller.Entities } } - if (query.IsYearMismatched.HasValue) - { - var filterValue = query.IsYearMismatched.Value; - - if (IsYearMismatched(item, libraryManager) != filterValue) - { - return false; - } - } - if (query.HasOfficialRating.HasValue) { var filterValue = query.HasOfficialRating.Value; @@ -1979,34 +1964,6 @@ namespace MediaBrowser.Controller.Entities return _userViewManager.GetUserSubView(parent.Id.ToString("N"), type, sortName, CancellationToken.None); } - public static bool IsYearMismatched(BaseItem item, ILibraryManager libraryManager) - { - if (item.ProductionYear.HasValue) - { - var path = item.Path; - - if (!string.IsNullOrEmpty(path)) - { - var info = libraryManager.ParseName(Path.GetFileName(path)); - var yearInName = info.Year; - - // Go up a level if we didn't get a year - if (!yearInName.HasValue) - { - info = libraryManager.ParseName(Path.GetFileName(Path.GetDirectoryName(path))); - yearInName = info.Year; - } - - if (yearInName.HasValue) - { - return yearInName.Value != item.ProductionYear.Value; - } - } - } - - return false; - } - public static IEnumerable FilterForAdjacency(IEnumerable items, string adjacentToId) { var list = items.ToList(); diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index 0df6c338c..5b3419639 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -56,8 +56,8 @@ ..\packages\Interfaces.IO.1.0.0.5\lib\portable-net45+sl4+wp71+win8+wpa81\Interfaces.IO.dll - - ..\packages\MediaBrowser.Naming.1.0.0.50\lib\portable-net45+sl4+wp71+win8+wpa81\MediaBrowser.Naming.dll + + ..\packages\MediaBrowser.Naming.1.0.0.51\lib\portable-net45+sl4+wp71+win8+wpa81\MediaBrowser.Naming.dll True diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index c00c4bf30..a67f7b675 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -85,10 +85,13 @@ namespace MediaBrowser.Server.Implementations.Persistence private IDbCommand _deleteItemValuesCommand; private IDbCommand _saveItemValuesCommand; + private IDbCommand _deleteProviderIdsCommand; + private IDbCommand _saveProviderIdsCommand; + private IDbCommand _updateInheritedRatingCommand; private IDbCommand _updateInheritedTagsCommand; - public const int LatestSchemaVersion = 82; + public const int LatestSchemaVersion = 83; /// /// Initializes a new instance of the class. @@ -143,6 +146,9 @@ namespace MediaBrowser.Server.Implementations.Persistence "create table if not exists ItemValues (ItemId GUID, Type INT, Value TEXT)", "create index if not exists idx_ItemValues on ItemValues(ItemId)", + "create table if not exists ProviderIds (ItemId GUID, Name TEXT, Value TEXT)", + "create index if not exists Idx_ProviderIds on ProviderIds(ItemId)", + "create table if not exists People (ItemId GUID, Name TEXT NOT NULL, Role TEXT, PersonType TEXT, SortOrder int, ListOrder int)", "create index if not exists idxPeopleItemId on People(ItemId)", "create index if not exists idxPeopleName on People(Name)", @@ -548,6 +554,17 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@Type"); _saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@Value"); + // provider ids + _deleteProviderIdsCommand = _connection.CreateCommand(); + _deleteProviderIdsCommand.CommandText = "delete from ProviderIds where ItemId=@Id"; + _deleteProviderIdsCommand.Parameters.Add(_deleteProviderIdsCommand, "@Id"); + + _saveProviderIdsCommand = _connection.CreateCommand(); + _saveProviderIdsCommand.CommandText = "insert into ProviderIds (ItemId, Name, Value) values (@ItemId, @Name, @Value)"; + _saveProviderIdsCommand.Parameters.Add(_saveProviderIdsCommand, "@ItemId"); + _saveProviderIdsCommand.Parameters.Add(_saveProviderIdsCommand, "@Name"); + _saveProviderIdsCommand.Parameters.Add(_saveProviderIdsCommand, "@Value"); + } /// @@ -862,6 +879,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } UpdateUserDataKeys(item.Id, item.GetUserDataKeys().Distinct(StringComparer.OrdinalIgnoreCase).ToList(), transaction); + UpdateProviderIds(item.Id, item.ProviderIds, transaction); UpdateItemValues(item.Id, GetItemValues(item), transaction); } @@ -1635,6 +1653,8 @@ namespace MediaBrowser.Server.Implementations.Persistence var excludeIds = query.ExcludeItemIds.ToList(); excludeIds.Add(item.Id.ToString("N")); query.ExcludeItemIds = excludeIds.ToArray(); + + query.ExcludeProviderIds = item.ProviderIds; } return list.ToArray(); @@ -2711,6 +2731,37 @@ namespace MediaBrowser.Server.Implementations.Persistence whereClauses.Add(string.Join(" AND ", excludeIds.ToArray())); } + if (query.ExcludeProviderIds.Count > 0) + { + var excludeIds = new List(); + + var index = 0; + foreach (var pair in query.ExcludeProviderIds) + { + var paramName = "@ExcludeProviderId" + index; + excludeIds.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Imdb'), '') <> "+ paramName + ")"); + cmd.Parameters.Add(cmd, paramName, DbType.String).Value = pair.Value; + index++; + } + + whereClauses.Add(string.Join(" AND ", excludeIds.ToArray())); + } + + if (query.HasImdbId.HasValue) + { + whereClauses.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Imdb'), '') <> '')"); + } + + if (query.HasTmdbId.HasValue) + { + whereClauses.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Tmdb'), '') <> '')"); + } + + if (query.HasTvdbId.HasValue) + { + whereClauses.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Tvdb'), '') <> '')"); + } + if (query.AlbumNames.Length > 0) { var clause = "("; @@ -3121,6 +3172,11 @@ namespace MediaBrowser.Server.Implementations.Persistence _deleteItemValuesCommand.Transaction = transaction; _deleteItemValuesCommand.ExecuteNonQuery(); + // Delete provider ids + _deleteProviderIdsCommand.GetParameter(0).Value = id; + _deleteProviderIdsCommand.Transaction = transaction; + _deleteProviderIdsCommand.ExecuteNonQuery(); + // Delete the item _deleteItemCommand.GetParameter(0).Value = id; _deleteItemCommand.Transaction = transaction; @@ -3337,6 +3393,37 @@ namespace MediaBrowser.Server.Implementations.Persistence return list; } + private void UpdateProviderIds(Guid itemId, Dictionary values, IDbTransaction transaction) + { + if (itemId == Guid.Empty) + { + throw new ArgumentNullException("itemId"); + } + + if (values == null) + { + throw new ArgumentNullException("keys"); + } + + CheckDisposed(); + + // First delete + _deleteProviderIdsCommand.GetParameter(0).Value = itemId; + _deleteProviderIdsCommand.Transaction = transaction; + + _deleteProviderIdsCommand.ExecuteNonQuery(); + + foreach (var pair in values) + { + _saveProviderIdsCommand.GetParameter(0).Value = itemId; + _saveProviderIdsCommand.GetParameter(1).Value = pair.Key; + _saveProviderIdsCommand.GetParameter(2).Value = pair.Value; + _saveProviderIdsCommand.Transaction = transaction; + + _saveProviderIdsCommand.ExecuteNonQuery(); + } + } + private void UpdateItemValues(Guid itemId, List> values, IDbTransaction transaction) { if (itemId == Guid.Empty) diff --git a/MediaBrowser.Server.Implementations/packages.config b/MediaBrowser.Server.Implementations/packages.config index 9d1aa2c33..516bf3271 100644 --- a/MediaBrowser.Server.Implementations/packages.config +++ b/MediaBrowser.Server.Implementations/packages.config @@ -4,7 +4,7 @@ - + From e50a74e35b5e3749f2a76e4a823441d64a34becd Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 2 Jun 2016 00:43:13 -0400 Subject: [PATCH 2/4] update provider id queries --- .../Persistence/SqliteItemRepository.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index a67f7b675..13f7a0d37 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -2739,7 +2739,7 @@ namespace MediaBrowser.Server.Implementations.Persistence foreach (var pair in query.ExcludeProviderIds) { var paramName = "@ExcludeProviderId" + index; - excludeIds.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Imdb'), '') <> "+ paramName + ")"); + excludeIds.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Imdb'), '') <> " + paramName + ")"); cmd.Parameters.Add(cmd, paramName, DbType.String).Value = pair.Value; index++; } @@ -2749,17 +2749,20 @@ namespace MediaBrowser.Server.Implementations.Persistence if (query.HasImdbId.HasValue) { - whereClauses.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Imdb'), '') <> '')"); + var fn = query.HasImdbId.Value ? "<>" : "="; + whereClauses.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Imdb'), '') " + fn + " '')"); } if (query.HasTmdbId.HasValue) { - whereClauses.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Tmdb'), '') <> '')"); + var fn = query.HasTmdbId.Value ? "<>" : "="; + whereClauses.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Tmdb'), '') " + fn + " '')"); } if (query.HasTvdbId.HasValue) { - whereClauses.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Tvdb'), '') <> '')"); + var fn = query.HasTvdbId.Value ? "<>" : "="; + whereClauses.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Tvdb'), '') " + fn + " '')"); } if (query.AlbumNames.Length > 0) @@ -3393,7 +3396,7 @@ namespace MediaBrowser.Server.Implementations.Persistence return list; } - private void UpdateProviderIds(Guid itemId, Dictionary values, IDbTransaction transaction) + private void UpdateProviderIds(Guid itemId, Dictionary values, IDbTransaction transaction) { if (itemId == Guid.Empty) { From 4884864e2c802c7998348d269b85ac267037f869 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 2 Jun 2016 02:40:16 -0400 Subject: [PATCH 3/4] config page --- MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 93873d4fe..d528686db 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -140,6 +140,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + PreserveNewest From 85c508bcd1e09355b9881bdc243c511e81bc621c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 2 Jun 2016 12:17:35 -0400 Subject: [PATCH 4/4] update provider setting --- .../Persistence/SqliteItemRepository.cs | 5 ++--- MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj | 3 --- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 13f7a0d37..494e1b12f 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -91,7 +91,7 @@ namespace MediaBrowser.Server.Implementations.Persistence private IDbCommand _updateInheritedRatingCommand; private IDbCommand _updateInheritedTagsCommand; - public const int LatestSchemaVersion = 83; + public const int LatestSchemaVersion = 84; /// /// Initializes a new instance of the class. @@ -132,7 +132,6 @@ namespace MediaBrowser.Server.Implementations.Persistence string[] queries = { "create table if not exists TypedBaseItems (guid GUID primary key, type TEXT, data BLOB, ParentId GUID, Path TEXT)", - "create index if not exists idx_TypedBaseItems on TypedBaseItems(guid)", "create index if not exists idx_PathTypedBaseItems on TypedBaseItems(Path)", "create index if not exists idx_ParentIdTypedBaseItems on TypedBaseItems(ParentId)", @@ -146,7 +145,7 @@ namespace MediaBrowser.Server.Implementations.Persistence "create table if not exists ItemValues (ItemId GUID, Type INT, Value TEXT)", "create index if not exists idx_ItemValues on ItemValues(ItemId)", - "create table if not exists ProviderIds (ItemId GUID, Name TEXT, Value TEXT)", + "create table if not exists ProviderIds (ItemId GUID, Name TEXT, Value TEXT, PRIMARY KEY (ItemId, Name))", "create index if not exists Idx_ProviderIds on ProviderIds(ItemId)", "create table if not exists People (ItemId GUID, Name TEXT NOT NULL, Role TEXT, PersonType TEXT, SortOrder int, ListOrder int)", diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index d528686db..1d860ed29 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -137,9 +137,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest