From 50b6d8b8ba83644f846c324132ec7d2f1e0a2391 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 14 Jun 2016 16:59:30 -0400 Subject: [PATCH 1/4] continue jquery removal --- MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs b/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs index 4aff3b6ef..abef5db59 100644 --- a/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs +++ b/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs @@ -136,6 +136,7 @@ namespace MediaBrowser.Server.Implementations.TV }).Cast().FirstOrDefault(); + // series is fully played if (firstUnwatchedEpisode == null) { return new Tuple(null, DateTime.MinValue, true); From 2f39ad1673671c7f81b0e4948f37ae35b029ca0f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 14 Jun 2016 22:15:51 -0400 Subject: [PATCH 2/4] encapsulate order by --- .../Persistence/SqliteItemRepository.cs | 73 ++++++++++++------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 4e851053b..ed429286f 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -1694,6 +1694,33 @@ namespace MediaBrowser.Server.Implementations.Persistence return " left join UserDataDb.UserData on (select UserDataKey from UserDataKeys where ItemId=Guid order by Priority LIMIT 1)=UserDataDb.UserData.Key"; } + private string GetGroupBy(InternalItemsQuery query) + { + var groups = new List(); + + if (!string.IsNullOrWhiteSpace(query.GroupByAncestorOfType)) + { + groups.Add("(Select PresentationUniqueKey from TypedBaseItems B where B.Type = 'MediaBrowser.Controller.Entities.TV.Series' And B.Guid in (Select AncestorId from AncestorIds where ItemId=A.Guid))"); + } + + if (EnableGroupByPresentationUniqueKey(query)) + { + groups.Add("PresentationUniqueKey"); + } + + if (groups.Count > 0) + { + return " Group by " + string.Join(",", groups.ToArray()); + } + + return string.Empty; + } + + private string GetFromText() + { + return " from TypedBaseItems A"; + } + public IEnumerable GetItemList(InternalItemsQuery query) { if (query == null) @@ -1707,7 +1734,7 @@ namespace MediaBrowser.Server.Implementations.Persistence using (var cmd = _connection.CreateCommand()) { - cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, _retriveItemColumns, cmd)) + " from TypedBaseItems"; + cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, _retriveItemColumns, cmd)) + GetFromText(); cmd.CommandText += GetJoinUserDataText(query); if (EnableJoinUserData(query)) @@ -1723,10 +1750,7 @@ namespace MediaBrowser.Server.Implementations.Persistence cmd.CommandText += whereText; - if (EnableGroupByPresentationUniqueKey(query)) - { - cmd.CommandText += " Group by PresentationUniqueKey"; - } + cmd.CommandText += GetGroupBy(query); cmd.CommandText += GetOrderByText(query); @@ -1797,7 +1821,7 @@ namespace MediaBrowser.Server.Implementations.Persistence using (var cmd = _connection.CreateCommand()) { - cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, _retriveItemColumns, cmd)) + " from TypedBaseItems"; + cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, _retriveItemColumns, cmd)) + GetFromText(); cmd.CommandText += GetJoinUserDataText(query); if (EnableJoinUserData(query)) @@ -1817,10 +1841,7 @@ namespace MediaBrowser.Server.Implementations.Persistence cmd.CommandText += whereText; - if (EnableGroupByPresentationUniqueKey(query)) - { - cmd.CommandText += " Group by PresentationUniqueKey"; - } + cmd.CommandText += GetGroupBy(query); cmd.CommandText += GetOrderByText(query); @@ -1838,11 +1859,11 @@ namespace MediaBrowser.Server.Implementations.Persistence if (EnableGroupByPresentationUniqueKey(query)) { - cmd.CommandText += "; select count (distinct PresentationUniqueKey) from TypedBaseItems"; + cmd.CommandText += "; select count (distinct PresentationUniqueKey)" + GetFromText(); } else { - cmd.CommandText += "; select count (guid) from TypedBaseItems"; + cmd.CommandText += "; select count (guid)" + GetFromText(); } cmd.CommandText += GetJoinUserDataText(query); @@ -1994,7 +2015,7 @@ namespace MediaBrowser.Server.Implementations.Persistence using (var cmd = _connection.CreateCommand()) { - cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, new[] { "guid" }, cmd)) + " from TypedBaseItems"; + cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, new[] { "guid" }, cmd)) + GetFromText(); cmd.CommandText += GetJoinUserDataText(query); if (EnableJoinUserData(query)) @@ -2010,10 +2031,7 @@ namespace MediaBrowser.Server.Implementations.Persistence cmd.CommandText += whereText; - if (EnableGroupByPresentationUniqueKey(query)) - { - cmd.CommandText += " Group by PresentationUniqueKey"; - } + cmd.CommandText += GetGroupBy(query); cmd.CommandText += GetOrderByText(query); @@ -2070,10 +2088,7 @@ namespace MediaBrowser.Server.Implementations.Persistence cmd.CommandText += whereText; - if (EnableGroupByPresentationUniqueKey(query)) - { - cmd.CommandText += " Group by PresentationUniqueKey"; - } + cmd.CommandText += GetGroupBy(query); cmd.CommandText += GetOrderByText(query); @@ -2137,7 +2152,7 @@ namespace MediaBrowser.Server.Implementations.Persistence using (var cmd = _connection.CreateCommand()) { - cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, new[] { "guid" }, cmd)) + " from TypedBaseItems"; + cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, new[] { "guid" }, cmd)) + GetFromText(); var whereClauses = GetWhereClauses(query, cmd); cmd.CommandText += GetJoinUserDataText(query); @@ -2153,10 +2168,7 @@ namespace MediaBrowser.Server.Implementations.Persistence cmd.CommandText += whereText; - if (EnableGroupByPresentationUniqueKey(query)) - { - cmd.CommandText += " Group by PresentationUniqueKey"; - } + cmd.CommandText += GetGroupBy(query); cmd.CommandText += GetOrderByText(query); @@ -2174,11 +2186,11 @@ namespace MediaBrowser.Server.Implementations.Persistence if (EnableGroupByPresentationUniqueKey(query)) { - cmd.CommandText += "; select count (distinct PresentationUniqueKey) from TypedBaseItems"; + cmd.CommandText += "; select count (distinct PresentationUniqueKey)" + GetFromText(); } else { - cmd.CommandText += "; select count (guid) from TypedBaseItems"; + cmd.CommandText += "; select count (guid)" + GetFromText(); } cmd.CommandText += GetJoinUserDataText(query); @@ -2370,6 +2382,11 @@ namespace MediaBrowser.Server.Implementations.Persistence whereClauses.Add("ParentIndexNumber=@ParentIndexNumber"); cmd.Parameters.Add(cmd, "@ParentIndexNumber", DbType.Int32).Value = query.ParentIndexNumber.Value; } + if (query.ParentIndexNumberNotEquals.HasValue) + { + whereClauses.Add("(ParentIndexNumber<>@ParentIndexNumber or ParentIndexNumber is null)"); + cmd.Parameters.Add(cmd, "@ParentIndexNumber", DbType.Int32).Value = query.ParentIndexNumberNotEquals.Value; + } if (query.MinEndDate.HasValue) { whereClauses.Add("EndDate>=@MinEndDate"); From 7dd2b1592cd9bef7379f3cc14e24de610daf2eeb Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 14 Jun 2016 22:18:19 -0400 Subject: [PATCH 3/4] add index number filter --- MediaBrowser.Controller/Entities/InternalItemsQuery.cs | 3 ++- .../Persistence/SqliteItemRepository.cs | 8 ++++---- MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs | 6 ++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index 5b9d94fc2..d50f5b525 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -110,6 +110,7 @@ namespace MediaBrowser.Controller.Entities internal List ItemIdsFromPersonFilters { get; set; } public int? ParentIndexNumber { get; set; } + public int? ParentIndexNumberNotEquals { get; set; } public int? IndexNumber { get; set; } public int? MinParentalRating { get; set; } public int? MaxParentalRating { get; set; } @@ -141,7 +142,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 Dictionary ExcludeProviderIds { get; set; } public InternalItemsQuery() { diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index ed429286f..d04dc5728 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -1698,10 +1698,10 @@ namespace MediaBrowser.Server.Implementations.Persistence { var groups = new List(); - if (!string.IsNullOrWhiteSpace(query.GroupByAncestorOfType)) - { - groups.Add("(Select PresentationUniqueKey from TypedBaseItems B where B.Type = 'MediaBrowser.Controller.Entities.TV.Series' And B.Guid in (Select AncestorId from AncestorIds where ItemId=A.Guid))"); - } + //if (!string.IsNullOrWhiteSpace(query.GroupByAncestorOfType)) + //{ + // groups.Add("(Select PresentationUniqueKey from TypedBaseItems B where B.Type = 'MediaBrowser.Controller.Entities.TV.Series' And B.Guid in (Select AncestorId from AncestorIds where ItemId=A.Guid))"); + //} if (EnableGroupByPresentationUniqueKey(query)) { diff --git a/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs b/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs index abef5db59..82232ffae 100644 --- a/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs +++ b/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs @@ -132,7 +132,8 @@ namespace MediaBrowser.Server.Implementations.TV SortOrder = SortOrder.Ascending, Limit = 1, IsPlayed = false, - IsVirtualItem = false + IsVirtualItem = false, + ParentIndexNumberNotEquals = 0 }).Cast().FirstOrDefault(); @@ -149,7 +150,8 @@ namespace MediaBrowser.Server.Implementations.TV SortBy = new[] { ItemSortBy.DatePlayed }, SortOrder = SortOrder.Descending, Limit = 1, - IsVirtualItem = false + IsVirtualItem = false, + ParentIndexNumberNotEquals = 0 }).FirstOrDefault(); From 80863e13264e871599d44668824a40159b0b080e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 14 Jun 2016 23:12:32 -0400 Subject: [PATCH 4/4] fix button alignments --- .../Entities/InternalItemsQuery.cs | 1 + MediaBrowser.Model/Querying/ItemSortBy.cs | 1 + .../LiveTv/Listings/XmlTvListingsProvider.cs | 6 +++++- .../Persistence/SqliteItemRepository.cs | 16 ++++++++++------ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index d50f5b525..e193a9dad 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -143,6 +143,7 @@ namespace MediaBrowser.Controller.Entities public bool EnableTotalRecordCount { get; set; } public bool ForceDirect { get; set; } public Dictionary ExcludeProviderIds { get; set; } + public string GroupByAncestorOfType { get; set; } public InternalItemsQuery() { diff --git a/MediaBrowser.Model/Querying/ItemSortBy.cs b/MediaBrowser.Model/Querying/ItemSortBy.cs index 9c2926b54..6f4ebd0c5 100644 --- a/MediaBrowser.Model/Querying/ItemSortBy.cs +++ b/MediaBrowser.Model/Querying/ItemSortBy.cs @@ -85,5 +85,6 @@ namespace MediaBrowser.Model.Querying public const string GameSystem = "GameSystem"; public const string IsFavoriteOrLiked = "IsFavoriteOrLiked"; public const string DateLastContentAdded = "DateLastContentAdded"; + public const string SeriesDatePlayed = "SeriesDatePlayed"; } } diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index 07affb865..010ee80ff 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Emby.XmlTv.Classes; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; using MediaBrowser.Model.Logging; @@ -68,6 +69,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings Progress = new Progress() }).ConfigureAwait(false); + + Directory.CreateDirectory(Path.GetDirectoryName(cacheFile)); File.Copy(tempFile, cacheFile, true); return cacheFile; @@ -103,7 +106,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings ImageUrl = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source) ? p.Icon.Source : null, HasImage = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source), OfficialRating = p.Rating != null && !String.IsNullOrEmpty(p.Rating.Value) ? p.Rating.Value : null, - CommunityRating = p.StarRating.HasValue ? p.StarRating.Value : (float?)null + CommunityRating = p.StarRating.HasValue ? p.StarRating.Value : (float?)null, + SeriesId = p.IsSeries ? p.Title.GetMD5().ToString("N") : null }); } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index d04dc5728..02f5483c5 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -1698,10 +1698,10 @@ namespace MediaBrowser.Server.Implementations.Persistence { var groups = new List(); - //if (!string.IsNullOrWhiteSpace(query.GroupByAncestorOfType)) - //{ - // groups.Add("(Select PresentationUniqueKey from TypedBaseItems B where B.Type = 'MediaBrowser.Controller.Entities.TV.Series' And B.Guid in (Select AncestorId from AncestorIds where ItemId=A.Guid))"); - //} + if (!string.IsNullOrWhiteSpace(query.GroupByAncestorOfType)) + { + groups.Add("(Select PresentationUniqueKey from TypedBaseItems B where B.Type = 'MediaBrowser.Controller.Entities.TV.Series' And B.Guid in (Select AncestorId from AncestorIds where ItemId=A.Guid))"); + } if (EnableGroupByPresentationUniqueKey(query)) { @@ -1926,7 +1926,7 @@ namespace MediaBrowser.Server.Implementations.Persistence return " ORDER BY " + string.Join(",", query.SortBy.Select(i => { - var columnMap = MapOrderByField(i); + var columnMap = MapOrderByField(i, query); var columnAscending = isAscending; if (columnMap.Item2) { @@ -1939,7 +1939,7 @@ namespace MediaBrowser.Server.Implementations.Persistence }).ToArray()); } - private Tuple MapOrderByField(string name) + private Tuple MapOrderByField(string name, InternalItemsQuery query) { if (string.Equals(name, ItemSortBy.AirTime, StringComparison.OrdinalIgnoreCase)) { @@ -1998,6 +1998,10 @@ namespace MediaBrowser.Server.Implementations.Persistence { return new Tuple("(select value from itemvalues where ItemId=Guid and Type=3 LIMIT 1)", false); } + if (string.Equals(name, ItemSortBy.SeriesDatePlayed, StringComparison.OrdinalIgnoreCase)) + { + return new Tuple("(Select MAX(LastPlayedDate) from TypedBaseItems B"+ GetJoinUserDataText(query) + " where B.Guid in (Select ItemId from AncestorIds where AncestorId in (select guid from typedbaseitems c where C.Type = 'MediaBrowser.Controller.Entities.TV.Series' And C.Guid in (Select AncestorId from AncestorIds where ItemId=A.Guid))))", false); + } return new Tuple(name, false); }