Merge pull request #1845 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2016-06-14 23:13:13 -04:00 committed by GitHub
commit c91b608005
5 changed files with 65 additions and 34 deletions

View File

@ -110,6 +110,7 @@ namespace MediaBrowser.Controller.Entities
internal List<Guid> 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,8 @@ namespace MediaBrowser.Controller.Entities
public bool GroupByPresentationUniqueKey { get; set; }
public bool EnableTotalRecordCount { get; set; }
public bool ForceDirect { get; set; }
public Dictionary<string,string> ExcludeProviderIds { get; set; }
public Dictionary<string, string> ExcludeProviderIds { get; set; }
public string GroupByAncestorOfType { get; set; }
public InternalItemsQuery()
{

View File

@ -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";
}
}

View File

@ -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<Double>()
}).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
});
}

View File

@ -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<string>();
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<BaseItem> 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);
@ -1905,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)
{
@ -1918,7 +1939,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
}).ToArray());
}
private Tuple<string, bool> MapOrderByField(string name)
private Tuple<string, bool> MapOrderByField(string name, InternalItemsQuery query)
{
if (string.Equals(name, ItemSortBy.AirTime, StringComparison.OrdinalIgnoreCase))
{
@ -1977,6 +1998,10 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
return new Tuple<string, bool>("(select value from itemvalues where ItemId=Guid and Type=3 LIMIT 1)", false);
}
if (string.Equals(name, ItemSortBy.SeriesDatePlayed, StringComparison.OrdinalIgnoreCase))
{
return new Tuple<string, bool>("(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<string, bool>(name, false);
}
@ -1994,7 +2019,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 +2035,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 +2092,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 +2156,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 +2172,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 +2190,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 +2386,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");

View File

@ -132,10 +132,12 @@ namespace MediaBrowser.Server.Implementations.TV
SortOrder = SortOrder.Ascending,
Limit = 1,
IsPlayed = false,
IsVirtualItem = false
IsVirtualItem = false,
ParentIndexNumberNotEquals = 0
}).Cast<Episode>().FirstOrDefault();
// series is fully played
if (firstUnwatchedEpisode == null)
{
return new Tuple<Episode, DateTime, bool>(null, DateTime.MinValue, true);
@ -148,7 +150,8 @@ namespace MediaBrowser.Server.Implementations.TV
SortBy = new[] { ItemSortBy.DatePlayed },
SortOrder = SortOrder.Descending,
Limit = 1,
IsVirtualItem = false
IsVirtualItem = false,
ParentIndexNumberNotEquals = 0
}).FirstOrDefault();