update db querying

This commit is contained in:
Luke Pulverenti 2016-03-20 15:53:22 -04:00
parent 6807b2dd71
commit b4ea519395
11 changed files with 144 additions and 180 deletions

View File

@ -258,7 +258,8 @@ namespace MediaBrowser.Api.Reports
MinPlayers = request.MinPlayers, MinPlayers = request.MinPlayers,
MaxPlayers = request.MaxPlayers, MaxPlayers = request.MaxPlayers,
MinCommunityRating = request.MinCommunityRating, MinCommunityRating = request.MinCommunityRating,
MinCriticRating = request.MinCriticRating MinCriticRating = request.MinCriticRating,
ParentIndexNumber = request.ParentIndexNumber
}; };
if (!string.IsNullOrWhiteSpace(request.Ids)) if (!string.IsNullOrWhiteSpace(request.Ids))
@ -312,6 +313,29 @@ namespace MediaBrowser.Api.Reports
query.MaxPremiereDate = DateTime.Parse(request.MaxPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); query.MaxPremiereDate = DateTime.Parse(request.MaxPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
} }
// Filter by Series Status
if (!string.IsNullOrEmpty(request.SeriesStatus))
{
query.SeriesStatuses = request.SeriesStatus.Split(',').Select(d => (SeriesStatus)Enum.Parse(typeof(SeriesStatus), d, true)).ToArray();
}
// Filter by Series AirDays
if (!string.IsNullOrEmpty(request.AirDays))
{
query.AirDays = request.AirDays.Split(',').Select(d => (DayOfWeek)Enum.Parse(typeof(DayOfWeek), d, true)).ToArray();
}
// ExcludeLocationTypes
if (!string.IsNullOrEmpty(request.ExcludeLocationTypes))
{
query.ExcludeLocationTypes = request.ExcludeLocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray();
}
if (!string.IsNullOrEmpty(request.LocationTypes))
{
query.LocationTypes = request.LocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray();
}
if (request.HasQueryLimit == false) if (request.HasQueryLimit == false)
{ {
query.StartIndex = null; query.StartIndex = null;
@ -452,26 +476,6 @@ namespace MediaBrowser.Api.Reports
} }
} }
// LocationTypes
if (!string.IsNullOrEmpty(request.LocationTypes))
{
var vals = request.LocationTypes.Split(',');
if (!vals.Contains(i.LocationType.ToString(), StringComparer.OrdinalIgnoreCase))
{
return false;
}
}
// ExcludeLocationTypes
if (!string.IsNullOrEmpty(request.ExcludeLocationTypes))
{
var vals = request.ExcludeLocationTypes.Split(',');
if (vals.Contains(i.LocationType.ToString(), StringComparer.OrdinalIgnoreCase))
{
return false;
}
}
if (!string.IsNullOrEmpty(request.AlbumArtistStartsWithOrGreater)) if (!string.IsNullOrEmpty(request.AlbumArtistStartsWithOrGreater))
{ {
var ok = new[] { i }.OfType<IHasAlbumArtist>() var ok = new[] { i }.OfType<IHasAlbumArtist>()
@ -483,57 +487,6 @@ namespace MediaBrowser.Api.Reports
} }
} }
// Filter by Series Status
if (!string.IsNullOrEmpty(request.SeriesStatus))
{
var vals = request.SeriesStatus.Split(',');
var ok = new[] { i }.OfType<Series>().Any(p => p.Status.HasValue && vals.Contains(p.Status.Value.ToString(), StringComparer.OrdinalIgnoreCase));
if (!ok)
{
return false;
}
}
// Filter by Series AirDays
if (!string.IsNullOrEmpty(request.AirDays))
{
var days = request.AirDays.Split(',').Select(d => (DayOfWeek)Enum.Parse(typeof(DayOfWeek), d, true));
var ok = new[] { i }.OfType<Series>().Any(p => p.AirDays != null && days.Any(d => p.AirDays.Contains(d)));
if (!ok)
{
return false;
}
}
if (request.ParentIndexNumber.HasValue)
{
var filterValue = request.ParentIndexNumber.Value;
var episode = i as Episode;
if (episode != null)
{
if (episode.ParentIndexNumber.HasValue && episode.ParentIndexNumber.Value != filterValue)
{
return false;
}
}
var song = i as Audio;
if (song != null)
{
if (song.ParentIndexNumber.HasValue && song.ParentIndexNumber.Value != filterValue)
{
return false;
}
}
}
if (request.AiredDuringSeason.HasValue) if (request.AiredDuringSeason.HasValue)
{ {
var episode = i as Episode; var episode = i as Episode;

View File

@ -231,7 +231,8 @@ namespace MediaBrowser.Api.UserLibrary
MaxPlayers = request.MaxPlayers, MaxPlayers = request.MaxPlayers,
MinCommunityRating = request.MinCommunityRating, MinCommunityRating = request.MinCommunityRating,
MinCriticRating = request.MinCriticRating, MinCriticRating = request.MinCriticRating,
ParentId = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId) ParentId = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId),
ParentIndexNumber = request.ParentIndexNumber
}; };
if (!string.IsNullOrWhiteSpace(request.Ids)) if (!string.IsNullOrWhiteSpace(request.Ids))
@ -285,6 +286,29 @@ namespace MediaBrowser.Api.UserLibrary
query.MaxPremiereDate = DateTime.Parse(request.MaxPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); query.MaxPremiereDate = DateTime.Parse(request.MaxPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
} }
// Filter by Series Status
if (!string.IsNullOrEmpty(request.SeriesStatus))
{
query.SeriesStatuses = request.SeriesStatus.Split(',').Select(d => (SeriesStatus)Enum.Parse(typeof(SeriesStatus), d, true)).ToArray();
}
// Filter by Series AirDays
if (!string.IsNullOrEmpty(request.AirDays))
{
query.AirDays = request.AirDays.Split(',').Select(d => (DayOfWeek)Enum.Parse(typeof(DayOfWeek), d, true)).ToArray();
}
// ExcludeLocationTypes
if (!string.IsNullOrEmpty(request.ExcludeLocationTypes))
{
query.ExcludeLocationTypes = request.ExcludeLocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray();
}
if (!string.IsNullOrEmpty(request.LocationTypes))
{
query.LocationTypes = request.LocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray();
}
return query; return query;
} }
@ -410,26 +434,6 @@ namespace MediaBrowser.Api.UserLibrary
} }
} }
// LocationTypes
if (!string.IsNullOrEmpty(request.LocationTypes))
{
var vals = request.LocationTypes.Split(',');
if (!vals.Contains(i.LocationType.ToString(), StringComparer.OrdinalIgnoreCase))
{
return false;
}
}
// ExcludeLocationTypes
if (!string.IsNullOrEmpty(request.ExcludeLocationTypes))
{
var vals = request.ExcludeLocationTypes.Split(',');
if (vals.Contains(i.LocationType.ToString(), StringComparer.OrdinalIgnoreCase))
{
return false;
}
}
if (!string.IsNullOrEmpty(request.AlbumArtistStartsWithOrGreater)) if (!string.IsNullOrEmpty(request.AlbumArtistStartsWithOrGreater))
{ {
var ok = new[] { i }.OfType<IHasAlbumArtist>() var ok = new[] { i }.OfType<IHasAlbumArtist>()
@ -441,57 +445,6 @@ namespace MediaBrowser.Api.UserLibrary
} }
} }
// Filter by Series Status
if (!string.IsNullOrEmpty(request.SeriesStatus))
{
var vals = request.SeriesStatus.Split(',');
var ok = new[] { i }.OfType<Series>().Any(p => p.Status.HasValue && vals.Contains(p.Status.Value.ToString(), StringComparer.OrdinalIgnoreCase));
if (!ok)
{
return false;
}
}
// Filter by Series AirDays
if (!string.IsNullOrEmpty(request.AirDays))
{
var days = request.AirDays.Split(',').Select(d => (DayOfWeek)Enum.Parse(typeof(DayOfWeek), d, true));
var ok = new[] { i }.OfType<Series>().Any(p => p.AirDays != null && days.Any(d => p.AirDays.Contains(d)));
if (!ok)
{
return false;
}
}
if (request.ParentIndexNumber.HasValue)
{
var filterValue = request.ParentIndexNumber.Value;
var episode = i as Episode;
if (episode != null)
{
if (episode.ParentIndexNumber.HasValue && episode.ParentIndexNumber.Value != filterValue)
{
return false;
}
}
var song = i as Audio;
if (song != null)
{
if (song.ParentIndexNumber.HasValue && song.ParentIndexNumber.Value != filterValue)
{
return false;
}
}
}
if (request.AiredDuringSeason.HasValue) if (request.AiredDuringSeason.HasValue)
{ {
var episode = i as Episode; var episode = i as Episode;

View File

@ -1094,13 +1094,6 @@ namespace MediaBrowser.Controller.Entities
return true; return true;
} }
// Apply year filter
if (query.Years.Length > 0)
{
Logger.Debug("Query requires post-filtering due to Years");
return true;
}
// Apply official rating filter // Apply official rating filter
if (query.OfficialRatings.Length > 0) if (query.OfficialRatings.Length > 0)
{ {
@ -1139,12 +1132,6 @@ namespace MediaBrowser.Controller.Entities
return true; return true;
} }
if (query.Years.Length > 0)
{
Logger.Debug("Query requires post-filtering due to Years");
return true;
}
if (query.OfficialRatings.Length > 0) if (query.OfficialRatings.Length > 0)
{ {
Logger.Debug("Query requires post-filtering due to OfficialRatings"); Logger.Debug("Query requires post-filtering due to OfficialRatings");
@ -1205,6 +1192,18 @@ namespace MediaBrowser.Controller.Entities
return true; return true;
} }
if (query.AirDays.Length > 0)
{
Logger.Debug("Query requires post-filtering due to AirDays");
return true;
}
if (query.SeriesStatuses.Length > 0)
{
Logger.Debug("Query requires post-filtering due to SeriesStatuses");
return true;
}
return false; return false;
} }

View File

@ -103,17 +103,18 @@ namespace MediaBrowser.Controller.Entities
public string[] ChannelIds { get; set; } public string[] ChannelIds { get; set; }
internal List<Guid> ItemIdsFromPersonFilters { get; set; } internal List<Guid> ItemIdsFromPersonFilters { get; set; }
public int? ParentIndexNumber { get; set; }
public int? MaxParentalRating { get; set; } public int? MaxParentalRating { get; set; }
public bool? IsCurrentSchema { get; set; } public bool? IsCurrentSchema { get; set; }
public bool? HasDeadParentId { get; set; } public bool? HasDeadParentId { get; set; }
public bool? IsOffline { get; set; } public bool? IsOffline { get; set; }
public LocationType? LocationType { get; set; }
public Guid? ParentId { get; set; } public Guid? ParentId { get; set; }
public string[] AncestorIds { get; set; } public string[] AncestorIds { get; set; }
public string[] TopParentIds { get; set; } public string[] TopParentIds { get; set; }
public LocationType[] LocationTypes { get; set; }
public LocationType[] ExcludeLocationTypes { get; set; } public LocationType[] ExcludeLocationTypes { get; set; }
public string[] PresetViews { get; set; } public string[] PresetViews { get; set; }
public SourceType[] SourceTypes { get; set; } public SourceType[] SourceTypes { get; set; }
@ -121,6 +122,9 @@ namespace MediaBrowser.Controller.Entities
public TrailerType[] TrailerTypes { get; set; } public TrailerType[] TrailerTypes { get; set; }
public TrailerType[] ExcludeTrailerTypes { get; set; } public TrailerType[] ExcludeTrailerTypes { get; set; }
public DayOfWeek[] AirDays { get; set; }
public SeriesStatus[] SeriesStatuses { get; set; }
public InternalItemsQuery() public InternalItemsQuery()
{ {
BlockUnratedItems = new UnratedItem[] { }; BlockUnratedItems = new UnratedItem[] { };
@ -144,12 +148,15 @@ namespace MediaBrowser.Controller.Entities
AncestorIds = new string[] { }; AncestorIds = new string[] { };
TopParentIds = new string[] { }; TopParentIds = new string[] { };
ExcludeTags = new string[] { }; ExcludeTags = new string[] { };
LocationTypes = new LocationType[] { };
ExcludeLocationTypes = new LocationType[] { }; ExcludeLocationTypes = new LocationType[] { };
PresetViews = new string[] { }; PresetViews = new string[] { };
SourceTypes = new SourceType[] { }; SourceTypes = new SourceType[] { };
ExcludeSourceTypes = new SourceType[] { }; ExcludeSourceTypes = new SourceType[] { };
TrailerTypes = new TrailerType[] { }; TrailerTypes = new TrailerType[] { };
ExcludeTrailerTypes = new TrailerType[] { }; ExcludeTrailerTypes = new TrailerType[] { };
AirDays = new DayOfWeek[] { };
SeriesStatuses = new SeriesStatus[] { };
} }
public InternalItemsQuery(User user) public InternalItemsQuery(User user)

View File

@ -1709,6 +1709,34 @@ namespace MediaBrowser.Controller.Entities
} }
} }
if (query.ParentIndexNumber.HasValue)
{
var filterValue = query.ParentIndexNumber.Value;
if (item.ParentIndexNumber.HasValue && item.ParentIndexNumber.Value != filterValue)
{
return false;
}
}
if (query.AirDays.Length > 0)
{
var ok = new[] { item }.OfType<Series>().Any(p => p.AirDays != null && query.AirDays.Any(d => p.AirDays.Contains(d)));
if (!ok)
{
return false;
}
}
if (query.SeriesStatuses.Length > 0)
{
var ok = new[] { item }.OfType<Series>().Any(p => p.Status.HasValue && query.SeriesStatuses.Contains(p.Status.Value));
if (!ok)
{
return false;
}
}
return true; return true;
} }

View File

@ -225,7 +225,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
{ {
var result = _itemRepo.GetItemIdsWithPath(new InternalItemsQuery var result = _itemRepo.GetItemIdsWithPath(new InternalItemsQuery
{ {
LocationType = LocationType.FileSystem, LocationTypes = new[] { LocationType.FileSystem },
//Limit = limit, //Limit = limit,
// These have their own cleanup routines // These have their own cleanup routines

View File

@ -1809,11 +1809,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
whereClauses.Add("IsOffline=@IsOffline"); whereClauses.Add("IsOffline=@IsOffline");
cmd.Parameters.Add(cmd, "@IsOffline", DbType.Boolean).Value = query.IsOffline; cmd.Parameters.Add(cmd, "@IsOffline", DbType.Boolean).Value = query.IsOffline;
} }
if (query.LocationType.HasValue)
{
whereClauses.Add("LocationType=@LocationType");
cmd.Parameters.Add(cmd, "@LocationType", DbType.String).Value = query.LocationType.Value;
}
if (query.IsMovie.HasValue) if (query.IsMovie.HasValue)
{ {
whereClauses.Add("IsMovie=@IsMovie"); whereClauses.Add("IsMovie=@IsMovie");
@ -1906,6 +1901,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
// cmd.Parameters.Add(cmd, "@MaxPlayers", DbType.Int32).Value = query.MaxPlayers.Value; // cmd.Parameters.Add(cmd, "@MaxPlayers", DbType.Int32).Value = query.MaxPlayers.Value;
//} //}
if (query.ParentIndexNumber.HasValue)
{
whereClauses.Add("ParentIndexNumber=@MinEndDate");
cmd.Parameters.Add(cmd, "@ParentIndexNumber", DbType.Int32).Value = query.ParentIndexNumber.Value;
}
if (query.MinEndDate.HasValue) if (query.MinEndDate.HasValue)
{ {
whereClauses.Add("EndDate>=@MinEndDate"); whereClauses.Add("EndDate>=@MinEndDate");
@ -2087,12 +2087,36 @@ namespace MediaBrowser.Server.Implementations.Persistence
whereClauses.Add("ParentId NOT NULL AND ParentId NOT IN (select guid from TypedBaseItems)"); whereClauses.Add("ParentId NOT NULL AND ParentId NOT IN (select guid from TypedBaseItems)");
} }
} }
if (query.Years.Length == 1)
{
whereClauses.Add("ProductionYear=@Years");
cmd.Parameters.Add(cmd, "@Years", DbType.Int32).Value = query.Years[0].ToString();
}
else if (query.Years.Length > 1)
{
var val = string.Join(",", query.Years.ToArray());
whereClauses.Add("ProductionYear in (" + val + ")");
}
if (query.LocationTypes.Length == 1)
{
whereClauses.Add("LocationType=@LocationType");
cmd.Parameters.Add(cmd, "@LocationType", DbType.String).Value = query.LocationTypes[0].ToString();
}
else if (query.LocationTypes.Length > 1)
{
var val = string.Join(",", query.LocationTypes.Select(i => "'" + i + "'").ToArray());
whereClauses.Add("LocationType in (" + val + ")");
}
if (query.ExcludeLocationTypes.Length == 1) if (query.ExcludeLocationTypes.Length == 1)
{ {
whereClauses.Add("LocationType<>@LocationType"); whereClauses.Add("LocationType<>@ExcludeLocationTypes");
cmd.Parameters.Add(cmd, "@LocationType", DbType.String).Value = query.ExcludeLocationTypes[0].ToString(); cmd.Parameters.Add(cmd, "@ExcludeLocationTypes", DbType.String).Value = query.ExcludeLocationTypes[0].ToString();
} }
if (query.ExcludeLocationTypes.Length > 1) else if (query.ExcludeLocationTypes.Length > 1)
{ {
var val = string.Join(",", query.ExcludeLocationTypes.Select(i => "'" + i + "'").ToArray()); var val = string.Join(",", query.ExcludeLocationTypes.Select(i => "'" + i + "'").ToArray());

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata> <metadata>
<id>MediaBrowser.Common.Internal</id> <id>MediaBrowser.Common.Internal</id>
<version>3.0.643</version> <version>3.0.644</version>
<title>MediaBrowser.Common.Internal</title> <title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors> <authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners> <owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Emby Theater and Emby Server. Not intended for plugin developer consumption.</description> <description>Contains common components shared by Emby Theater and Emby Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Emby 2013</copyright> <copyright>Copyright © Emby 2013</copyright>
<dependencies> <dependencies>
<dependency id="MediaBrowser.Common" version="3.0.643" /> <dependency id="MediaBrowser.Common" version="3.0.644" />
<dependency id="NLog" version="4.2.3" /> <dependency id="NLog" version="4.2.3" />
<dependency id="SimpleInjector" version="3.1.2" /> <dependency id="SimpleInjector" version="3.1.2" />
</dependencies> </dependencies>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata> <metadata>
<id>MediaBrowser.Common</id> <id>MediaBrowser.Common</id>
<version>3.0.643</version> <version>3.0.644</version>
<title>MediaBrowser.Common</title> <title>MediaBrowser.Common</title>
<authors>Emby Team</authors> <authors>Emby Team</authors>
<owners>ebr,Luke,scottisafool</owners> <owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata> <metadata>
<id>MediaBrowser.Model.Signed</id> <id>MediaBrowser.Model.Signed</id>
<version>3.0.643</version> <version>3.0.644</version>
<title>MediaBrowser.Model - Signed Edition</title> <title>MediaBrowser.Model - Signed Edition</title>
<authors>Emby Team</authors> <authors>Emby Team</authors>
<owners>ebr,Luke,scottisafool</owners> <owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata> <metadata>
<id>MediaBrowser.Server.Core</id> <id>MediaBrowser.Server.Core</id>
<version>3.0.643</version> <version>3.0.644</version>
<title>Media Browser.Server.Core</title> <title>Media Browser.Server.Core</title>
<authors>Emby Team</authors> <authors>Emby Team</authors>
<owners>ebr,Luke,scottisafool</owners> <owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains core components required to build plugins for Emby Server.</description> <description>Contains core components required to build plugins for Emby Server.</description>
<copyright>Copyright © Emby 2013</copyright> <copyright>Copyright © Emby 2013</copyright>
<dependencies> <dependencies>
<dependency id="MediaBrowser.Common" version="3.0.643" /> <dependency id="MediaBrowser.Common" version="3.0.644" />
<dependency id="Interfaces.IO" version="1.0.0.5" /> <dependency id="Interfaces.IO" version="1.0.0.5" />
</dependencies> </dependencies>
</metadata> </metadata>