update series queries

This commit is contained in:
Luke Pulverenti 2016-12-06 03:24:29 -05:00
parent e9a3690079
commit 016d8301f5
15 changed files with 132 additions and 26 deletions

View File

@ -291,6 +291,7 @@ namespace Emby.Server.Implementations.Data
AddColumn(db, "TypedBaseItems", "Artists", "Text", existingColumnNames); AddColumn(db, "TypedBaseItems", "Artists", "Text", existingColumnNames);
AddColumn(db, "TypedBaseItems", "AlbumArtists", "Text", existingColumnNames); AddColumn(db, "TypedBaseItems", "AlbumArtists", "Text", existingColumnNames);
AddColumn(db, "TypedBaseItems", "ExternalId", "Text", existingColumnNames); AddColumn(db, "TypedBaseItems", "ExternalId", "Text", existingColumnNames);
AddColumn(db, "TypedBaseItems", "SeriesPresentationUniqueKey", "Text", existingColumnNames);
existingColumnNames = GetColumnNames(db, "ItemValues"); existingColumnNames = GetColumnNames(db, "ItemValues");
AddColumn(db, "ItemValues", "CleanValue", "Text", existingColumnNames); AddColumn(db, "ItemValues", "CleanValue", "Text", existingColumnNames);
@ -341,6 +342,7 @@ namespace Emby.Server.Implementations.Data
"drop index if exists Idx_ProviderIds1", "drop index if exists Idx_ProviderIds1",
"drop table if exists Images", "drop table if exists Images",
"drop index if exists idx_Images", "drop index if exists idx_Images",
"drop index if exists idx_TypeSeriesPresentationUniqueKey",
"create index if not exists idx_PathTypedBaseItems on TypedBaseItems(Path)", "create index if not exists idx_PathTypedBaseItems on TypedBaseItems(Path)",
"create index if not exists idx_ParentIdTypedBaseItems on TypedBaseItems(ParentId)", "create index if not exists idx_ParentIdTypedBaseItems on TypedBaseItems(ParentId)",
@ -353,6 +355,9 @@ namespace Emby.Server.Implementations.Data
// covering index // covering index
"create index if not exists idx_TopParentIdGuid on TypedBaseItems(TopParentId,Guid)", "create index if not exists idx_TopParentIdGuid on TypedBaseItems(TopParentId,Guid)",
// series
"create index if not exists idx_TypeSeriesPresentationUniqueKey1 on TypedBaseItems(Type,SeriesPresentationUniqueKey,PresentationUniqueKey,SortName)",
// live tv programs // live tv programs
"create index if not exists idx_TypeTopParentIdStartDate on TypedBaseItems(Type,TopParentId,StartDate)", "create index if not exists idx_TypeTopParentIdStartDate on TypedBaseItems(Type,TopParentId,StartDate)",
@ -488,7 +493,8 @@ namespace Emby.Server.Implementations.Data
"ExtraType", "ExtraType",
"Artists", "Artists",
"AlbumArtists", "AlbumArtists",
"ExternalId" "ExternalId",
"SeriesPresentationUniqueKey"
}; };
private readonly string[] _mediaStreamSaveColumns = private readonly string[] _mediaStreamSaveColumns =
@ -619,7 +625,8 @@ namespace Emby.Server.Implementations.Data
"ExtraType", "ExtraType",
"Artists", "Artists",
"AlbumArtists", "AlbumArtists",
"ExternalId" "ExternalId",
"SeriesPresentationUniqueKey"
}; };
var saveItemCommandCommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values ("; var saveItemCommandCommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (";
@ -1024,11 +1031,13 @@ namespace Emby.Server.Implementations.Data
{ {
saveItemStatement.TryBind("@SeriesId", hasSeries.SeriesId); saveItemStatement.TryBind("@SeriesId", hasSeries.SeriesId);
saveItemStatement.TryBind("@SeriesSortName", hasSeries.SeriesSortName); saveItemStatement.TryBind("@SeriesSortName", hasSeries.SeriesSortName);
saveItemStatement.TryBind("@SeriesPresentationUniqueKey", hasSeries.SeriesPresentationUniqueKey);
} }
else else
{ {
saveItemStatement.TryBindNull("@SeriesId"); saveItemStatement.TryBindNull("@SeriesId");
saveItemStatement.TryBindNull("@SeriesSortName"); saveItemStatement.TryBindNull("@SeriesSortName");
saveItemStatement.TryBindNull("@SeriesPresentationUniqueKey");
} }
saveItemStatement.TryBind("@ExternalSeriesId", item.ExternalSeriesId); saveItemStatement.TryBind("@ExternalSeriesId", item.ExternalSeriesId);
@ -1983,6 +1992,15 @@ namespace Emby.Server.Implementations.Data
} }
index++; index++;
if (hasSeries != null)
{
if (!reader.IsDBNull(index))
{
hasSeries.SeriesPresentationUniqueKey = reader.GetString(index);
}
}
index++;
if (string.IsNullOrWhiteSpace(item.Tagline)) if (string.IsNullOrWhiteSpace(item.Tagline))
{ {
var movie = item as Movie; var movie = item as Movie;
@ -4292,6 +4310,16 @@ namespace Emby.Server.Implementations.Data
} }
} }
if (!string.IsNullOrWhiteSpace(query.SeriesPresentationUniqueKey))
{
whereClauses.Add("SeriesPresentationUniqueKey=@SeriesPresentationUniqueKey");
if (statement != null)
{
statement.TryBind("@SeriesPresentationUniqueKey", query.SeriesPresentationUniqueKey);
}
}
if (query.BlockUnratedItems.Length == 1) if (query.BlockUnratedItems.Length == 1)
{ {
whereClauses.Add("(InheritedParentalRatingValue > 0 or UnratedType <> @UnratedType)"); whereClauses.Add("(InheritedParentalRatingValue > 0 or UnratedType <> @UnratedType)");

View File

@ -1057,6 +1057,12 @@ namespace Emby.Server.Implementations.Library
try try
{ {
await PerformLibraryValidation(progress, cancellationToken).ConfigureAwait(false); await PerformLibraryValidation(progress, cancellationToken).ConfigureAwait(false);
if (!ConfigurationManager.Configuration.EnableSeriesPresentationUniqueKey)
{
ConfigurationManager.Configuration.EnableSeriesPresentationUniqueKey = true;
ConfigurationManager.SaveConfiguration();
}
} }
finally finally
{ {
@ -1478,8 +1484,9 @@ namespace Emby.Server.Implementations.Library
!query.ParentId.HasValue && !query.ParentId.HasValue &&
query.ChannelIds.Length == 0 && query.ChannelIds.Length == 0 &&
query.TopParentIds.Length == 0 && query.TopParentIds.Length == 0 &&
string.IsNullOrWhiteSpace(query.AncestorWithPresentationUniqueKey) string.IsNullOrWhiteSpace(query.AncestorWithPresentationUniqueKey) &&
&& query.ItemIds.Length == 0) string.IsNullOrWhiteSpace(query.SeriesPresentationUniqueKey) &&
query.ItemIds.Length == 0)
{ {
var userViews = _userviewManager().GetUserViews(new UserViewQuery var userViews = _userviewManager().GetUserViews(new UserViewQuery
{ {

View File

@ -158,9 +158,13 @@ namespace Emby.Server.Implementations.TV
/// <returns>Task{Episode}.</returns> /// <returns>Task{Episode}.</returns>
private Tuple<DateTime, Func<Episode>> GetNextUp(Series series, User user) private Tuple<DateTime, Func<Episode>> GetNextUp(Series series, User user)
{ {
var enableSeriesPresentationKey = _config.Configuration.EnableSeriesPresentationUniqueKey;
var seriesKey = GetUniqueSeriesKey(series);
var lastWatchedEpisode = _libraryManager.GetItemList(new InternalItemsQuery(user) var lastWatchedEpisode = _libraryManager.GetItemList(new InternalItemsQuery(user)
{ {
AncestorWithPresentationUniqueKey = GetUniqueSeriesKey(series), AncestorWithPresentationUniqueKey = enableSeriesPresentationKey ? null : seriesKey,
SeriesPresentationUniqueKey = enableSeriesPresentationKey ? seriesKey : null,
IncludeItemTypes = new[] { typeof(Episode).Name }, IncludeItemTypes = new[] { typeof(Episode).Name },
SortBy = new[] { ItemSortBy.SortName }, SortBy = new[] { ItemSortBy.SortName },
SortOrder = SortOrder.Descending, SortOrder = SortOrder.Descending,
@ -174,7 +178,8 @@ namespace Emby.Server.Implementations.TV
{ {
return _libraryManager.GetItemList(new InternalItemsQuery(user) return _libraryManager.GetItemList(new InternalItemsQuery(user)
{ {
AncestorWithPresentationUniqueKey = GetUniqueSeriesKey(series), AncestorWithPresentationUniqueKey = enableSeriesPresentationKey ? null : seriesKey,
SeriesPresentationUniqueKey = enableSeriesPresentationKey ? seriesKey : null,
IncludeItemTypes = new[] { typeof(Episode).Name }, IncludeItemTypes = new[] { typeof(Episode).Name },
SortBy = new[] { ItemSortBy.SortName }, SortBy = new[] { ItemSortBy.SortName },
SortOrder = SortOrder.Ascending, SortOrder = SortOrder.Ascending,

View File

@ -119,6 +119,7 @@ namespace MediaBrowser.Api
config.SkipDeserializationForBasicTypes = true; config.SkipDeserializationForBasicTypes = true;
config.SkipDeserializationForPrograms = true; config.SkipDeserializationForPrograms = true;
config.SkipDeserializationForAudio = true; config.SkipDeserializationForAudio = true;
config.EnableSeriesPresentationUniqueKey = true;
} }
public void Post(UpdateStartupConfiguration request) public void Post(UpdateStartupConfiguration request)

View File

@ -18,6 +18,8 @@ namespace MediaBrowser.Controller.Entities
} }
} }
[IgnoreDataMember]
public string SeriesPresentationUniqueKey { get; set; }
[IgnoreDataMember] [IgnoreDataMember]
public string SeriesName { get; set; } public string SeriesName { get; set; }
[IgnoreDataMember] [IgnoreDataMember]
@ -33,6 +35,10 @@ namespace MediaBrowser.Controller.Entities
{ {
return SeriesName; return SeriesName;
} }
public string FindSeriesPresentationUniqueKey()
{
return SeriesPresentationUniqueKey;
}
[IgnoreDataMember] [IgnoreDataMember]
public override bool EnableRefreshOnDateModifiedChange public override bool EnableRefreshOnDateModifiedChange

View File

@ -15,5 +15,7 @@ namespace MediaBrowser.Controller.Entities
string FindSeriesSortName(); string FindSeriesSortName();
Guid? SeriesId { get; set; } Guid? SeriesId { get; set; }
Guid? FindSeriesId(); Guid? FindSeriesId();
string SeriesPresentationUniqueKey { get; set; }
string FindSeriesPresentationUniqueKey();
} }
} }

View File

@ -147,6 +147,7 @@ namespace MediaBrowser.Controller.Entities
public string[] ArtistNames { get; set; } public string[] ArtistNames { get; set; }
public string[] ExcludeArtistIds { get; set; } public string[] ExcludeArtistIds { get; set; }
public string AncestorWithPresentationUniqueKey { get; set; } public string AncestorWithPresentationUniqueKey { get; set; }
public string SeriesPresentationUniqueKey { get; set; }
public bool GroupByPresentationUniqueKey { get; set; } public bool GroupByPresentationUniqueKey { get; set; }
public bool EnableTotalRecordCount { get; set; } public bool EnableTotalRecordCount { get; set; }

View File

@ -165,13 +165,22 @@ namespace MediaBrowser.Controller.Entities.TV
{ {
return FindParent<Season>() != null; return FindParent<Season>() != null;
} }
} }
[IgnoreDataMember]
public string SeriesPresentationUniqueKey { get; set; }
[IgnoreDataMember] [IgnoreDataMember]
public string SeriesName { get; set; } public string SeriesName { get; set; }
[IgnoreDataMember] [IgnoreDataMember]
public string SeasonName { get; set; } public string SeasonName { get; set; }
public string FindSeriesPresentationUniqueKey()
{
var series = Series;
return series == null ? null : series.PresentationUniqueKey;
}
public string FindSeasonName() public string FindSeasonName()
{ {

View File

@ -207,12 +207,21 @@ namespace MediaBrowser.Controller.Entities.TV
return UnratedItem.Series; return UnratedItem.Series;
} }
[IgnoreDataMember]
public string SeriesPresentationUniqueKey { get; set; }
[IgnoreDataMember] [IgnoreDataMember]
public string SeriesName { get; set; } public string SeriesName { get; set; }
[IgnoreDataMember] [IgnoreDataMember]
public Guid? SeriesId { get; set; } public Guid? SeriesId { get; set; }
public string FindSeriesPresentationUniqueKey()
{
var series = Series;
return series == null ? null : series.PresentationUniqueKey;
}
public string FindSeriesName() public string FindSeriesName()
{ {
var series = Series; var series = Series;

View File

@ -95,12 +95,16 @@ namespace MediaBrowser.Controller.Entities.TV
public override string CreatePresentationUniqueKey() public override string CreatePresentationUniqueKey()
{ {
var userdatakeys = GetUserDataKeys(); if (LibraryManager.GetLibraryOptions(this).EnableAutomaticSeriesGrouping)
if (userdatakeys.Count > 1)
{ {
return AddLibrariesToPresentationUniqueKey(userdatakeys[0]); var userdatakeys = GetUserDataKeys();
if (userdatakeys.Count > 1)
{
return AddLibrariesToPresentationUniqueKey(userdatakeys[0]);
}
} }
return base.CreatePresentationUniqueKey(); return base.CreatePresentationUniqueKey();
} }
@ -131,9 +135,13 @@ namespace MediaBrowser.Controller.Entities.TV
public override int GetChildCount(User user) public override int GetChildCount(User user)
{ {
var enableSeriesPresentationKey = ConfigurationManager.Configuration.EnableSeriesPresentationUniqueKey;
var seriesKey = GetUniqueSeriesKey(this);
var result = LibraryManager.GetItemsResult(new InternalItemsQuery(user) var result = LibraryManager.GetItemsResult(new InternalItemsQuery(user)
{ {
AncestorWithPresentationUniqueKey = GetUniqueSeriesKey(this), AncestorWithPresentationUniqueKey = enableSeriesPresentationKey ? null : seriesKey,
SeriesPresentationUniqueKey = enableSeriesPresentationKey ? seriesKey : null,
IncludeItemTypes = new[] { typeof(Season).Name }, IncludeItemTypes = new[] { typeof(Season).Name },
IsVirtualItem = false, IsVirtualItem = false,
Limit = 0 Limit = 0
@ -144,9 +152,15 @@ namespace MediaBrowser.Controller.Entities.TV
public override int GetRecursiveChildCount(User user) public override int GetRecursiveChildCount(User user)
{ {
var query = new InternalItemsQuery(user); var enableSeriesPresentationKey = ConfigurationManager.Configuration.EnableSeriesPresentationUniqueKey;
var seriesKey = GetUniqueSeriesKey(this);
var query = new InternalItemsQuery(user)
{
AncestorWithPresentationUniqueKey = enableSeriesPresentationKey ? null : seriesKey,
SeriesPresentationUniqueKey = enableSeriesPresentationKey ? seriesKey : null,
};
query.AncestorWithPresentationUniqueKey = GetUniqueSeriesKey(this);
if (query.SortBy.Length == 0) if (query.SortBy.Length == 0)
{ {
query.SortBy = new[] { ItemSortBy.SortName }; query.SortBy = new[] { ItemSortBy.SortName };
@ -223,11 +237,13 @@ namespace MediaBrowser.Controller.Entities.TV
{ {
var config = user.Configuration; var config = user.Configuration;
var enableSeriesPresentationKey = ConfigurationManager.Configuration.EnableSeriesPresentationUniqueKey;
var seriesKey = GetUniqueSeriesKey(this); var seriesKey = GetUniqueSeriesKey(this);
var query = new InternalItemsQuery(user) var query = new InternalItemsQuery(user)
{ {
AncestorWithPresentationUniqueKey = seriesKey, AncestorWithPresentationUniqueKey = enableSeriesPresentationKey ? null : seriesKey,
SeriesPresentationUniqueKey = enableSeriesPresentationKey ? seriesKey : null,
IncludeItemTypes = new[] { typeof(Season).Name }, IncludeItemTypes = new[] { typeof(Season).Name },
SortBy = new[] { ItemSortBy.SortName } SortBy = new[] { ItemSortBy.SortName }
}; };
@ -259,7 +275,11 @@ namespace MediaBrowser.Controller.Entities.TV
if (query.Recursive) if (query.Recursive)
{ {
query.AncestorWithPresentationUniqueKey = GetUniqueSeriesKey(this); var enableSeriesPresentationKey = ConfigurationManager.Configuration.EnableSeriesPresentationUniqueKey;
var seriesKey = GetUniqueSeriesKey(this);
query.AncestorWithPresentationUniqueKey = enableSeriesPresentationKey ? null : seriesKey;
query.SeriesPresentationUniqueKey = enableSeriesPresentationKey ? seriesKey : null;
if (query.SortBy.Length == 0) if (query.SortBy.Length == 0)
{ {
query.SortBy = new[] { ItemSortBy.SortName }; query.SortBy = new[] { ItemSortBy.SortName };
@ -281,11 +301,13 @@ namespace MediaBrowser.Controller.Entities.TV
public IEnumerable<Episode> GetEpisodes(User user) public IEnumerable<Episode> GetEpisodes(User user)
{ {
var enableSeriesPresentationKey = ConfigurationManager.Configuration.EnableSeriesPresentationUniqueKey;
var seriesKey = GetUniqueSeriesKey(this); var seriesKey = GetUniqueSeriesKey(this);
var query = new InternalItemsQuery(user) var query = new InternalItemsQuery(user)
{ {
AncestorWithPresentationUniqueKey = seriesKey, AncestorWithPresentationUniqueKey = enableSeriesPresentationKey ? null : seriesKey,
SeriesPresentationUniqueKey = enableSeriesPresentationKey ? seriesKey : null,
IncludeItemTypes = new[] { typeof(Episode).Name, typeof(Season).Name }, IncludeItemTypes = new[] { typeof(Episode).Name, typeof(Season).Name },
SortBy = new[] { ItemSortBy.SortName } SortBy = new[] { ItemSortBy.SortName }
}; };
@ -387,14 +409,19 @@ namespace MediaBrowser.Controller.Entities.TV
public IEnumerable<Episode> GetSeasonEpisodes(Season parentSeason, User user) public IEnumerable<Episode> GetSeasonEpisodes(Season parentSeason, User user)
{ {
var enableSeriesPresentationKey = ConfigurationManager.Configuration.EnableSeriesPresentationUniqueKey;
var queryFromSeries = ConfigurationManager.Configuration.DisplaySpecialsWithinSeasons;
// add optimization when this setting is not enabled // add optimization when this setting is not enabled
var seriesKey = ConfigurationManager.Configuration.DisplaySpecialsWithinSeasons ? var seriesKey = queryFromSeries ?
GetUniqueSeriesKey(this) : GetUniqueSeriesKey(this) :
GetUniqueSeriesKey(parentSeason); GetUniqueSeriesKey(parentSeason);
var query = new InternalItemsQuery(user) var query = new InternalItemsQuery(user)
{ {
AncestorWithPresentationUniqueKey = seriesKey, AncestorWithPresentationUniqueKey = queryFromSeries && enableSeriesPresentationKey ? null : seriesKey,
SeriesPresentationUniqueKey = queryFromSeries && enableSeriesPresentationKey ? seriesKey : null,
IncludeItemTypes = new[] { typeof(Episode).Name }, IncludeItemTypes = new[] { typeof(Episode).Name },
SortBy = new[] { ItemSortBy.SortName } SortBy = new[] { ItemSortBy.SortName }
}; };

View File

@ -14,6 +14,7 @@
public bool SaveLocalMetadata { get; set; } public bool SaveLocalMetadata { get; set; }
public bool EnableInternetProviders { get; set; } public bool EnableInternetProviders { get; set; }
public bool ImportMissingEpisodes { get; set; } public bool ImportMissingEpisodes { get; set; }
public bool EnableAutomaticSeriesGrouping { get; set; }
public LibraryOptions() public LibraryOptions()
{ {
@ -21,6 +22,7 @@
EnableRealtimeMonitor = true; EnableRealtimeMonitor = true;
PathInfos = new MediaPathInfo[] { }; PathInfos = new MediaPathInfo[] { };
EnableInternetProviders = true; EnableInternetProviders = true;
EnableAutomaticSeriesGrouping = true;
} }
} }

View File

@ -46,6 +46,7 @@ namespace MediaBrowser.Model.Configuration
/// </summary> /// </summary>
/// <value><c>true</c> if [use HTTPS]; otherwise, <c>false</c>.</value> /// <value><c>true</c> if [use HTTPS]; otherwise, <c>false</c>.</value>
public bool EnableHttps { get; set; } public bool EnableHttps { get; set; }
public bool EnableSeriesPresentationUniqueKey { get; set; }
/// <summary> /// <summary>
/// Gets or sets the value pointing to the file system where the ssl certiifcate is located.. /// Gets or sets the value pointing to the file system where the ssl certiifcate is located..

View File

@ -55,6 +55,13 @@ namespace MediaBrowser.Providers.TV
updateType |= ItemUpdateType.MetadataImport; updateType |= ItemUpdateType.MetadataImport;
} }
var seriesPresentationUniqueKey = item.FindSeriesPresentationUniqueKey();
if (!string.Equals(item.SeriesPresentationUniqueKey, seriesPresentationUniqueKey, StringComparison.Ordinal))
{
item.SeriesPresentationUniqueKey = seriesPresentationUniqueKey;
updateType |= ItemUpdateType.MetadataImport;
}
return updateType; return updateType;
} }

View File

@ -51,6 +51,13 @@ namespace MediaBrowser.Providers.TV
updateType |= ItemUpdateType.MetadataImport; updateType |= ItemUpdateType.MetadataImport;
} }
var seriesPresentationUniqueKey = item.FindSeriesPresentationUniqueKey();
if (!string.Equals(item.SeriesPresentationUniqueKey, seriesPresentationUniqueKey, StringComparison.Ordinal))
{
item.SeriesPresentationUniqueKey = seriesPresentationUniqueKey;
updateType |= ItemUpdateType.MetadataImport;
}
var seriesId = item.FindSeriesId(); var seriesId = item.FindSeriesId();
if (item.SeriesId != seriesId) if (item.SeriesId != seriesId)
{ {

View File

@ -693,9 +693,6 @@
<Content Include="dashboard-ui\files\dummy.mp4"> <Content Include="dashboard-ui\files\dummy.mp4">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="dashboard-ui\librarypathmapping.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\metadatanfo.html"> <Content Include="dashboard-ui\metadatanfo.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@ -876,9 +873,6 @@
<Content Include="dashboard-ui\scripts\librarymenu.js"> <Content Include="dashboard-ui\scripts\librarymenu.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="dashboard-ui\scripts\librarypathmapping.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\metadatanfo.js"> <Content Include="dashboard-ui\scripts\metadatanfo.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>