update item queries
This commit is contained in:
parent
d7edd499d2
commit
f378a2c789
|
@ -114,7 +114,7 @@ namespace MediaBrowser.Api
|
|||
config.EnableStandaloneMusicKeys = true;
|
||||
config.EnableCaseSensitiveItemIds = true;
|
||||
config.EnableFolderView = true;
|
||||
config.SchemaVersion = 89;
|
||||
config.SchemaVersion = 91;
|
||||
}
|
||||
|
||||
public void Post(UpdateStartupConfiguration request)
|
||||
|
|
|
@ -53,6 +53,8 @@ namespace MediaBrowser.Controller.Channels
|
|||
|
||||
public bool IsInfiniteStream { get; set; }
|
||||
|
||||
public string HomePageUrl { get; set; }
|
||||
|
||||
public ChannelItemInfo()
|
||||
{
|
||||
MediaSources = new List<ChannelMediaInfo>();
|
||||
|
|
|
@ -71,6 +71,9 @@ namespace MediaBrowser.Controller.Entities
|
|||
|
||||
public List<ItemImageInfo> ImageInfos { get; set; }
|
||||
|
||||
[IgnoreDataMember]
|
||||
public bool IsVirtualItem { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the album.
|
||||
/// </summary>
|
||||
|
|
|
@ -117,6 +117,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
public bool? IsCurrentSchema { get; set; }
|
||||
public bool? HasDeadParentId { get; set; }
|
||||
public bool? IsOffline { get; set; }
|
||||
public bool? IsVirtualItem { get; set; }
|
||||
|
||||
public Guid? ParentId { get; set; }
|
||||
public string[] AncestorIds { get; set; }
|
||||
|
|
|
@ -128,39 +128,16 @@ namespace MediaBrowser.Controller.Entities.TV
|
|||
return IndexNumber != null ? IndexNumber.Value.ToString("0000") : Name;
|
||||
}
|
||||
|
||||
public override bool RequiresRefresh()
|
||||
{
|
||||
var result = base.RequiresRefresh();
|
||||
|
||||
if (!result)
|
||||
{
|
||||
if (!IsVirtualItem.HasValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public bool? IsVirtualItem { get; set; }
|
||||
|
||||
[IgnoreDataMember]
|
||||
public bool IsMissingSeason
|
||||
{
|
||||
get { return (IsVirtualItem ?? DetectIsVirtualItem()) && !IsUnaired; }
|
||||
get { return (IsVirtualItem) && !IsUnaired; }
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public bool IsVirtualUnaired
|
||||
{
|
||||
get { return (IsVirtualItem ?? DetectIsVirtualItem()) && IsUnaired; }
|
||||
}
|
||||
|
||||
private bool DetectIsVirtualItem()
|
||||
{
|
||||
return LocationType == LocationType.Virtual && GetEpisodes().All(i => i.LocationType == LocationType.Virtual);
|
||||
get { return (IsVirtualItem) && IsUnaired; }
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
|
|
|
@ -92,10 +92,7 @@ namespace MediaBrowser.Controller.Entities.TV
|
|||
{
|
||||
get
|
||||
{
|
||||
return GetRecursiveChildren(i => i is Episode)
|
||||
.Select(i => i.DateCreated)
|
||||
.OrderByDescending(i => i)
|
||||
.FirstOrDefault();
|
||||
return DateLastMediaAdded ?? DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,6 +237,7 @@ namespace MediaBrowser.Controller.Entities.TV
|
|||
AncestorWithPresentationUniqueKey = PresentationUniqueKey,
|
||||
IncludeItemTypes = new[] { typeof(Episode).Name, typeof(Season).Name },
|
||||
SortBy = new[] { ItemSortBy.SortName }
|
||||
|
||||
}).ToList();
|
||||
|
||||
var allSeriesEpisodes = allItems.OfType<Episode>().ToList();
|
||||
|
|
|
@ -428,7 +428,8 @@ namespace MediaBrowser.Providers.TV
|
|||
Name = name,
|
||||
IndexNumber = episodeNumber,
|
||||
ParentIndexNumber = seasonNumber,
|
||||
Id = _libraryManager.GetNewItemId((series.Id + seasonNumber.ToString(_usCulture) + name), typeof(Episode))
|
||||
Id = _libraryManager.GetNewItemId((series.Id + seasonNumber.ToString(_usCulture) + name), typeof(Episode)),
|
||||
IsVirtualItem = true
|
||||
};
|
||||
|
||||
episode.SetParent(season);
|
||||
|
|
|
@ -1307,6 +1307,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
item.OfficialRating = info.OfficialRating;
|
||||
item.DateCreated = info.DateCreated ?? DateTime.UtcNow;
|
||||
item.Tags = info.Tags;
|
||||
item.HomePageUrl = info.HomePageUrl;
|
||||
}
|
||||
|
||||
var trailer = item as Trailer;
|
||||
|
|
|
@ -202,23 +202,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
{
|
||||
var user = _userManager.GetUserById(request.UserId);
|
||||
|
||||
var includeTypes = request.IncludeItemTypes;
|
||||
|
||||
var currentUser = user;
|
||||
|
||||
var libraryItems = GetItemsForLatestItems(user, request.ParentId, includeTypes, request.Limit ?? 10).Where(i =>
|
||||
{
|
||||
if (request.IsPlayed.HasValue)
|
||||
{
|
||||
var val = request.IsPlayed.Value;
|
||||
if (i is Video && i.IsPlayed(currentUser) != val)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
var libraryItems = GetItemsForLatestItems(user, request);
|
||||
|
||||
var list = new List<Tuple<BaseItem, List<BaseItem>>>();
|
||||
|
||||
|
@ -254,8 +238,13 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
return list;
|
||||
}
|
||||
|
||||
private IEnumerable<BaseItem> GetItemsForLatestItems(User user, string parentId, string[] includeItemTypes, int limit)
|
||||
private IEnumerable<BaseItem> GetItemsForLatestItems(User user, LatestItemsQuery request)
|
||||
{
|
||||
var parentId = request.ParentId;
|
||||
|
||||
var includeItemTypes = request.IncludeItemTypes;
|
||||
var limit = request.Limit ?? 10;
|
||||
|
||||
var parentIds = string.IsNullOrEmpty(parentId)
|
||||
? new string[] { }
|
||||
: new[] { parentId };
|
||||
|
@ -276,7 +265,12 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
|
||||
var excludeItemTypes = includeItemTypes.Length == 0 ? new[]
|
||||
{
|
||||
typeof(Person).Name, typeof(Studio).Name, typeof(Year).Name, typeof(GameGenre).Name, typeof(MusicGenre).Name, typeof(Genre).Name
|
||||
typeof(Person).Name,
|
||||
typeof(Studio).Name,
|
||||
typeof(Year).Name,
|
||||
typeof(GameGenre).Name,
|
||||
typeof(MusicGenre).Name,
|
||||
typeof(Genre).Name
|
||||
|
||||
} : new string[] { };
|
||||
|
||||
|
@ -288,8 +282,9 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
IsFolder = includeItemTypes.Length == 0 ? false : (bool?)null,
|
||||
ExcludeItemTypes = excludeItemTypes,
|
||||
ExcludeLocationTypes = new[] { LocationType.Virtual },
|
||||
Limit = limit * 20,
|
||||
ExcludeSourceTypes = parentIds.Length == 0 ? new[] { SourceType.Channel, SourceType.LiveTV } : new SourceType[] { }
|
||||
Limit = limit * 5,
|
||||
ExcludeSourceTypes = parentIds.Length == 0 ? new[] { SourceType.Channel, SourceType.LiveTV } : new SourceType[] { },
|
||||
IsPlayed = request.IsPlayed
|
||||
|
||||
}, parentIds);
|
||||
}
|
||||
|
|
|
@ -952,7 +952,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
|||
|
||||
if (query.Limit.HasValue)
|
||||
{
|
||||
internalQuery.Limit = Math.Max(query.Limit.Value * 5, 200);
|
||||
internalQuery.Limit = Math.Max(query.Limit.Value * 4, 200);
|
||||
}
|
||||
|
||||
if (query.HasAired.HasValue)
|
||||
|
|
|
@ -58,7 +58,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
|
||||
private readonly string _criticReviewsPath;
|
||||
|
||||
public const int LatestSchemaVersion = 89;
|
||||
public const int LatestSchemaVersion = 91;
|
||||
|
||||
private IDbConnection _connection;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
|
||||
|
@ -88,9 +90,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
|
||||
//AttachUserDataDb(connection);
|
||||
|
||||
//connection.RunQueries(new []
|
||||
//connection.RunQueries(new[]
|
||||
//{
|
||||
// "pragma locking_mode=EXCLUSIVE"
|
||||
// "pragma locking_mode=NORMAL"
|
||||
|
||||
//}, Logger);
|
||||
|
||||
|
@ -105,6 +107,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
/// <returns>Task.</returns>
|
||||
public async Task Initialize(IDbConnector dbConnector)
|
||||
{
|
||||
//_connection = await CreateConnection().ConfigureAwait(false);
|
||||
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
var createMediaStreamsTableCommand
|
||||
|
@ -115,7 +119,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
"create table if not exists TypedBaseItems (guid GUID primary key, type TEXT, data BLOB, ParentId GUID, Path TEXT)",
|
||||
"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_TypedBaseItems2 on TypedBaseItems(Type,Guid)",
|
||||
|
||||
"create table if not exists AncestorIds (ItemId GUID, AncestorId GUID, AncestorIdText TEXT, PRIMARY KEY (ItemId, AncestorId))",
|
||||
"create index if not exists idx_AncestorIds1 on AncestorIds(AncestorId)",
|
||||
|
@ -234,9 +237,14 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
string[] postQueries =
|
||||
{
|
||||
"create index if not exists idx_PresentationUniqueKey on TypedBaseItems(PresentationUniqueKey)",
|
||||
"create index if not exists idx_GuidType on TypedBaseItems(Guid,Type)",
|
||||
"create index if not exists idx_Type on TypedBaseItems(Type)",
|
||||
"create index if not exists idx_TopParentId on TypedBaseItems(TopParentId)",
|
||||
"create index if not exists idx_TypeTopParentId on TypedBaseItems(Type,TopParentId)"
|
||||
"create index if not exists idx_TypeTopParentId on TypedBaseItems(Type,TopParentId)",
|
||||
"create index if not exists idx_TypeTopParentId2 on TypedBaseItems(TopParentId,MediaType,IsVirtualItem)",
|
||||
"create index if not exists idx_TypeTopParentId3 on TypedBaseItems(TopParentId,IsFolder,IsVirtualItem)",
|
||||
"create index if not exists idx_TypeTopParentId4 on TypedBaseItems(TopParentId,Type,IsVirtualItem)",
|
||||
"create index if not exists idx_TypeTopParentId5 on TypedBaseItems(TopParentId,IsVirtualItem)"
|
||||
};
|
||||
|
||||
connection.RunQueries(postQueries, Logger);
|
||||
|
@ -727,15 +735,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
|
||||
saveItemCommand.GetParameter(index++).Value = item.Album;
|
||||
|
||||
var season = item as Season;
|
||||
if (season != null && season.IsVirtualItem.HasValue)
|
||||
{
|
||||
saveItemCommand.GetParameter(index++).Value = season.IsVirtualItem.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
saveItemCommand.GetParameter(index++).Value = null;
|
||||
}
|
||||
saveItemCommand.GetParameter(index++).Value = item.IsVirtualItem || (!item.IsFolder && item.LocationType == LocationType.Virtual);
|
||||
|
||||
var hasSeries = item as IHasSeries;
|
||||
if (hasSeries != null)
|
||||
|
@ -1167,10 +1167,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
item.CriticRatingSummary = reader.GetString(57);
|
||||
}
|
||||
|
||||
var season = item as Season;
|
||||
if (season != null && !reader.IsDBNull(58))
|
||||
if (!reader.IsDBNull(58))
|
||||
{
|
||||
season.IsVirtualItem = reader.GetBoolean(58);
|
||||
item.IsVirtualItem = reader.GetBoolean(58);
|
||||
}
|
||||
|
||||
return item;
|
||||
|
@ -1651,7 +1650,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
var slowThreshold = 1000;
|
||||
|
||||
#if DEBUG
|
||||
slowThreshold = 100;
|
||||
slowThreshold = 30;
|
||||
#endif
|
||||
|
||||
if (elapsed >= slowThreshold)
|
||||
|
@ -2196,18 +2195,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
cmd.Parameters.Add(cmd, "@IsFolder", DbType.Boolean).Value = query.IsFolder;
|
||||
}
|
||||
|
||||
var includeTypes = query.IncludeItemTypes.SelectMany(MapIncludeItemTypes).ToArray();
|
||||
if (includeTypes.Length == 1)
|
||||
{
|
||||
whereClauses.Add("type=@type");
|
||||
cmd.Parameters.Add(cmd, "@type", DbType.String).Value = includeTypes[0];
|
||||
}
|
||||
else if (includeTypes.Length > 1)
|
||||
{
|
||||
var inClause = string.Join(",", includeTypes.Select(i => "'" + i + "'").ToArray());
|
||||
whereClauses.Add(string.Format("type in ({0})", inClause));
|
||||
}
|
||||
|
||||
var excludeTypes = query.ExcludeItemTypes.SelectMany(MapIncludeItemTypes).ToArray();
|
||||
if (excludeTypes.Length == 1)
|
||||
{
|
||||
|
@ -2220,6 +2207,18 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
whereClauses.Add(string.Format("type not in ({0})", inClause));
|
||||
}
|
||||
|
||||
var includeTypes = query.IncludeItemTypes.SelectMany(MapIncludeItemTypes).ToArray();
|
||||
if (includeTypes.Length == 1)
|
||||
{
|
||||
whereClauses.Add("type=@type");
|
||||
cmd.Parameters.Add(cmd, "@type", DbType.String).Value = includeTypes[0];
|
||||
}
|
||||
else if (includeTypes.Length > 1)
|
||||
{
|
||||
var inClause = string.Join(",", includeTypes.Select(i => "'" + i + "'").ToArray());
|
||||
whereClauses.Add(string.Format("type in ({0})", inClause));
|
||||
}
|
||||
|
||||
if (query.ChannelIds.Length == 1)
|
||||
{
|
||||
whereClauses.Add("ChannelId=@ChannelId");
|
||||
|
@ -2635,8 +2634,15 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
|
||||
if (query.LocationTypes.Length == 1)
|
||||
{
|
||||
whereClauses.Add("LocationType=@LocationType");
|
||||
cmd.Parameters.Add(cmd, "@LocationType", DbType.String).Value = query.LocationTypes[0].ToString();
|
||||
if (query.LocationTypes[0] == LocationType.Virtual && _config.Configuration.SchemaVersion >= 90)
|
||||
{
|
||||
query.IsVirtualItem = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
whereClauses.Add("LocationType=@LocationType");
|
||||
cmd.Parameters.Add(cmd, "@LocationType", DbType.String).Value = query.LocationTypes[0].ToString();
|
||||
}
|
||||
}
|
||||
else if (query.LocationTypes.Length > 1)
|
||||
{
|
||||
|
@ -2646,8 +2652,15 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
}
|
||||
if (query.ExcludeLocationTypes.Length == 1)
|
||||
{
|
||||
whereClauses.Add("LocationType<>@ExcludeLocationTypes");
|
||||
cmd.Parameters.Add(cmd, "@ExcludeLocationTypes", DbType.String).Value = query.ExcludeLocationTypes[0].ToString();
|
||||
if (query.ExcludeLocationTypes[0] == LocationType.Virtual && _config.Configuration.SchemaVersion >= 90)
|
||||
{
|
||||
query.IsVirtualItem = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
whereClauses.Add("LocationType<>@ExcludeLocationTypes");
|
||||
cmd.Parameters.Add(cmd, "@ExcludeLocationTypes", DbType.String).Value = query.ExcludeLocationTypes[0].ToString();
|
||||
}
|
||||
}
|
||||
else if (query.ExcludeLocationTypes.Length > 1)
|
||||
{
|
||||
|
@ -2655,6 +2668,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
|
||||
whereClauses.Add("LocationType not in (" + val + ")");
|
||||
}
|
||||
if (query.IsVirtualItem.HasValue)
|
||||
{
|
||||
whereClauses.Add("IsVirtualItem=@IsVirtualItem");
|
||||
cmd.Parameters.Add(cmd, "@IsVirtualItem", DbType.Boolean).Value = query.IsVirtualItem.Value;
|
||||
}
|
||||
if (query.MediaTypes.Length == 1)
|
||||
{
|
||||
whereClauses.Add("MediaType=@MediaTypes");
|
||||
|
|
Loading…
Reference in New Issue
Block a user