From 1fcbd3c6da5bd061473a3f34a6410c9bbce0fc13 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 5 Jul 2016 02:01:31 -0400 Subject: [PATCH] denormalize seriesid --- MediaBrowser.Api/StartupWizardService.cs | 2 +- MediaBrowser.Controller/Entities/Book.cs | 9 ++++- .../Entities/IHasSeries.cs | 5 ++- .../Entities/TV/Episode.cs | 9 ++++- MediaBrowser.Controller/Entities/TV/Season.cs | 8 +++++ MediaBrowser.Model/Querying/ItemFields.cs | 2 ++ .../TV/MissingEpisodeProvider.cs | 3 +- .../Dto/DtoService.cs | 35 ++++++++++++------- .../Library/Resolvers/TV/EpisodeResolver.cs | 29 +++++++++------ .../Persistence/SqliteItemRepository.cs | 26 ++++++++++++-- 10 files changed, 97 insertions(+), 31 deletions(-) diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 8f4a62ced..a59cc6909 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -117,7 +117,7 @@ namespace MediaBrowser.Api config.EnableStandaloneMusicKeys = true; config.EnableCaseSensitiveItemIds = true; //config.EnableFolderView = true; - config.SchemaVersion = 100; + config.SchemaVersion = 101; } public void Post(UpdateStartupConfiguration request) diff --git a/MediaBrowser.Controller/Entities/Book.cs b/MediaBrowser.Controller/Entities/Book.cs index 76f54edea..34368d61f 100644 --- a/MediaBrowser.Controller/Entities/Book.cs +++ b/MediaBrowser.Controller/Entities/Book.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Providers; +using System; +using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Configuration; using System.Linq; using System.Runtime.Serialization; @@ -19,12 +20,18 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public string SeriesName { get; set; } + public Guid? SeriesId { get; set; } public string FindSeriesName() { return SeriesName; } + public Guid? FindSeriesId() + { + return SeriesId; + } + public override bool CanDownload() { var locationType = LocationType; diff --git a/MediaBrowser.Controller/Entities/IHasSeries.cs b/MediaBrowser.Controller/Entities/IHasSeries.cs index 1a262ed28..d4dbb8ef6 100644 --- a/MediaBrowser.Controller/Entities/IHasSeries.cs +++ b/MediaBrowser.Controller/Entities/IHasSeries.cs @@ -1,4 +1,6 @@  +using System; + namespace MediaBrowser.Controller.Entities { public interface IHasSeries @@ -8,7 +10,8 @@ namespace MediaBrowser.Controller.Entities /// /// The name of the series. string SeriesName { get; set; } - string FindSeriesName(); + Guid? SeriesId { get; set; } + Guid? FindSeriesId(); } } diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.cs index 4ff1813ff..b13c291d1 100644 --- a/MediaBrowser.Controller/Entities/TV/Episode.cs +++ b/MediaBrowser.Controller/Entities/TV/Episode.cs @@ -248,7 +248,14 @@ namespace MediaBrowser.Controller.Entities.TV } [IgnoreDataMember] - public Guid? SeasonId { get; set; } + public Guid? SeasonId { get; set; } + public Guid? SeriesId { get; set; } + + public Guid? FindSeriesId() + { + var series = Series; + return series == null ? (Guid?)null : series.Id; + } public override IEnumerable GetAncestorIds() { diff --git a/MediaBrowser.Controller/Entities/TV/Season.cs b/MediaBrowser.Controller/Entities/TV/Season.cs index a689ca550..218d0fef8 100644 --- a/MediaBrowser.Controller/Entities/TV/Season.cs +++ b/MediaBrowser.Controller/Entities/TV/Season.cs @@ -237,12 +237,20 @@ namespace MediaBrowser.Controller.Entities.TV [IgnoreDataMember] public string SeriesName { get; set; } + public Guid? SeriesId { get; set; } + public string FindSeriesName() { var series = Series; return series == null ? SeriesName : series.Name; } + public Guid? FindSeriesId() + { + var series = Series; + return series == null ? (Guid?)null : series.Id; + } + /// /// Gets the lookup information. /// diff --git a/MediaBrowser.Model/Querying/ItemFields.cs b/MediaBrowser.Model/Querying/ItemFields.cs index cea638a39..21f87247a 100644 --- a/MediaBrowser.Model/Querying/ItemFields.cs +++ b/MediaBrowser.Model/Querying/ItemFields.cs @@ -197,6 +197,8 @@ /// SeriesGenres, + SeriesPrimaryImage, + /// /// The series studio /// diff --git a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs index e8a0057fe..22e126795 100644 --- a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs @@ -430,7 +430,8 @@ namespace MediaBrowser.Providers.TV ParentIndexNumber = seasonNumber, Id = _libraryManager.GetNewItemId((series.Id + seasonNumber.ToString(_usCulture) + name), typeof(Episode)), IsVirtualItem = true, - SeasonId = season == null ? (Guid?)null : season.Id + SeasonId = season == null ? (Guid?)null : season.Id, + SeriesId = series.Id }; episode.SetParent(season); diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 257448941..925afa428 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -1316,6 +1316,12 @@ namespace MediaBrowser.Server.Implementations.Dto dto.SeasonName = episode.SeasonName; + var seriesId = episode.SeriesId; + if (seriesId.HasValue) + { + dto.SeriesId = seriesId.Value.ToString("N"); + } + Series episodeSeries = null; if (fields.Contains(ItemFields.SeriesGenres)) @@ -1327,13 +1333,7 @@ namespace MediaBrowser.Server.Implementations.Dto } } - episodeSeries = episodeSeries ?? episode.Series; - if (episodeSeries != null) - { - dto.SeriesId = GetDtoId(episodeSeries); - } - - if (options.GetImageLimit(ImageType.Primary) > 0) + if (fields.Contains(ItemFields.SeriesPrimaryImage)) { episodeSeries = episodeSeries ?? episode.Series; if (episodeSeries != null) @@ -1369,18 +1369,27 @@ namespace MediaBrowser.Server.Implementations.Dto { dto.SeriesName = season.SeriesName; - series = season.Series; - - if (series != null) + var seriesId = season.SeriesId; + if (seriesId.HasValue) { - dto.SeriesId = GetDtoId(series); + dto.SeriesId = seriesId.Value.ToString("N"); + } - if (fields.Contains(ItemFields.SeriesStudio)) + series = null; + + if (fields.Contains(ItemFields.SeriesStudio)) + { + series = series ?? season.Series; + if (series != null) { dto.SeriesStudio = series.Studios.FirstOrDefault(); } + } - if (options.GetImageLimit(ImageType.Primary) > 0) + if (fields.Contains(ItemFields.SeriesPrimaryImage)) + { + series = series ?? season.Series; + if (series != null) { dto.SeriesPrimaryImageTag = GetImageCacheTag(series, ImageType.Primary); } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs index e279a978e..6d0f4ffe2 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs @@ -30,23 +30,32 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV return null; } - var season = parent as Season; - - // Just in case the user decided to nest episodes. - // Not officially supported but in some cases we can handle it. - if (season == null) - { - season = parent.GetParents().OfType().FirstOrDefault(); - } - // If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something // Also handle flat tv folders - if (season != null || args.HasParent() || string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) { var episode = ResolveVideo(args, false); if (episode != null) { + var season = parent as Season; + // Just in case the user decided to nest episodes. + // Not officially supported but in some cases we can handle it. + if (season == null) + { + season = parent.GetParents().OfType().FirstOrDefault(); + } + + var series = parent as Series; + if (series == null) + { + series = parent.GetParents().OfType().FirstOrDefault(); + } + + if (series != null) + { + episode.SeriesId = series.Id; + } if (season != null) { episode.SeasonId = season.Id; diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index e239c3b83..4a70ddc2e 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -95,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Persistence private IDbCommand _updateInheritedRatingCommand; private IDbCommand _updateInheritedTagsCommand; - public const int LatestSchemaVersion = 100; + public const int LatestSchemaVersion = 101; /// /// Initializes a new instance of the class. @@ -273,6 +273,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(Logger, "TypedBaseItems", "UserDataKey", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "SeasonName", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "SeasonId", "GUID"); + _connection.AddColumn(Logger, "TypedBaseItems", "SeriesId", "GUID"); _connection.AddColumn(Logger, "UserDataKeys", "Priority", "INT"); _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text"); @@ -407,7 +408,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "IsVirtualItem", "SeriesName", "SeasonName", - "SeasonId" + "SeasonId", + "SeriesId" }; private readonly string[] _mediaStreamSaveColumns = @@ -529,7 +531,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "SeriesName", "UserDataKey", "SeasonName", - "SeasonId" + "SeasonId", + "SeriesId" }; _saveItemCommand = _connection.CreateCommand(); _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values ("; @@ -972,6 +975,15 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = null; } + if (hasSeries != null) + { + _saveItemCommand.GetParameter(index++).Value = hasSeries.FindSeriesId(); + } + else + { + _saveItemCommand.GetParameter(index++).Value = null; + } + _saveItemCommand.Transaction = transaction; _saveItemCommand.ExecuteNonQuery(); @@ -1416,6 +1428,14 @@ namespace MediaBrowser.Server.Implementations.Persistence } } + if (hasSeries != null) + { + if (!reader.IsDBNull(62)) + { + hasSeries.SeriesId = reader.GetGuid(62); + } + } + return item; }