update item queries
This commit is contained in:
parent
76586d3a49
commit
67dc2a0bf9
|
@ -286,7 +286,7 @@ namespace MediaBrowser.Api
|
||||||
StartIndex = request.StartIndex,
|
StartIndex = request.StartIndex,
|
||||||
Limit = request.Limit
|
Limit = request.Limit
|
||||||
|
|
||||||
}, user, parentIds);
|
}, parentIds);
|
||||||
|
|
||||||
var options = GetDtoOptions(request);
|
var options = GetDtoOptions(request);
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,8 @@ namespace MediaBrowser.Controller.Entities
|
||||||
public Guid? ParentId { get; set; }
|
public Guid? ParentId { get; set; }
|
||||||
public string[] AncestorIds { get; set; }
|
public string[] AncestorIds { get; set; }
|
||||||
|
|
||||||
|
public LocationType[] ExcludeLocationTypes { get; set; }
|
||||||
|
|
||||||
public InternalItemsQuery()
|
public InternalItemsQuery()
|
||||||
{
|
{
|
||||||
Tags = new string[] { };
|
Tags = new string[] { };
|
||||||
|
@ -123,6 +125,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
ChannelIds = new string[] { };
|
ChannelIds = new string[] { };
|
||||||
ItemIds = new string[] { };
|
ItemIds = new string[] { };
|
||||||
AncestorIds = new string[] { };
|
AncestorIds = new string[] { };
|
||||||
|
ExcludeLocationTypes = new LocationType[] { };
|
||||||
}
|
}
|
||||||
|
|
||||||
public InternalItemsQuery(User user)
|
public InternalItemsQuery(User user)
|
||||||
|
|
|
@ -560,6 +560,6 @@ namespace MediaBrowser.Controller.Library
|
||||||
/// <param name="user">The user.</param>
|
/// <param name="user">The user.</param>
|
||||||
/// <param name="parentIds">The parent ids.</param>
|
/// <param name="parentIds">The parent ids.</param>
|
||||||
/// <returns>QueryResult<BaseItem>.</returns>
|
/// <returns>QueryResult<BaseItem>.</returns>
|
||||||
QueryResult<BaseItem> GetItemsResult(InternalItemsQuery query, User user, IEnumerable<string> parentIds);
|
QueryResult<BaseItem> GetItemsResult(InternalItemsQuery query, IEnumerable<string> parentIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -139,5 +139,10 @@ namespace MediaBrowser.Controller.LiveTv
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool IsVisibleStandalone(User user)
|
||||||
|
{
|
||||||
|
return IsVisible(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,5 +149,10 @@ namespace MediaBrowser.Controller.LiveTv
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool IsVisibleStandalone(User user)
|
||||||
|
{
|
||||||
|
return IsVisible(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -489,7 +489,7 @@ namespace MediaBrowser.Dlna.ContentDirectory
|
||||||
Limit = limit,
|
Limit = limit,
|
||||||
StartIndex = startIndex
|
StartIndex = startIndex
|
||||||
|
|
||||||
}, user, new string[] { });
|
}, new string[] { });
|
||||||
|
|
||||||
var serverItems = itemsResult.Items.Select(i => new ServerItem
|
var serverItems = itemsResult.Items.Select(i => new ServerItem
|
||||||
{
|
{
|
||||||
|
|
|
@ -1297,21 +1297,32 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
|
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
|
AddUserToQuery(query, user);
|
||||||
items = items.Where(i => i.IsVisibleStandalone(user));
|
items = items.Where(i => i.IsVisibleStandalone(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryResult<BaseItem> GetItemsResult(InternalItemsQuery query, User user, IEnumerable<string> parentIds)
|
public QueryResult<BaseItem> GetItemsResult(InternalItemsQuery query, IEnumerable<string> parentIds)
|
||||||
{
|
{
|
||||||
var parents = parentIds.Select(i => GetItemById(new Guid(i))).ToList();
|
var parents = parentIds.Select(i => GetItemById(new Guid(i))).ToList();
|
||||||
|
|
||||||
query.AncestorIds = parents.SelectMany(i => i.GetIdsForAncestorQuery()).Select(i => i.ToString("N")).ToArray();
|
query.AncestorIds = parents.SelectMany(i => i.GetIdsForAncestorQuery()).Select(i => i.ToString("N")).ToArray();
|
||||||
|
|
||||||
|
if (query.User != null)
|
||||||
|
{
|
||||||
|
AddUserToQuery(query, query.User);
|
||||||
|
}
|
||||||
|
|
||||||
return GetItems(query);
|
return GetItems(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AddUserToQuery(InternalItemsQuery query, User user)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the intros.
|
/// Gets the intros.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -245,16 +245,8 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
|
|
||||||
var currentUser = user;
|
var currentUser = user;
|
||||||
|
|
||||||
Func<BaseItem, bool> filter = i =>
|
var libraryItems = GetItemsForLatestItems(user, request.ParentId, includeTypes).Where(i =>
|
||||||
{
|
{
|
||||||
if (includeTypes.Length > 0)
|
|
||||||
{
|
|
||||||
if (!includeTypes.Contains(i.GetType().Name, StringComparer.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.IsPlayed.HasValue)
|
if (request.IsPlayed.HasValue)
|
||||||
{
|
{
|
||||||
var val = request.IsPlayed.Value;
|
var val = request.IsPlayed.Value;
|
||||||
|
@ -264,29 +256,12 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return i.LocationType != LocationType.Virtual && !i.IsFolder;
|
return true;
|
||||||
};
|
});
|
||||||
|
|
||||||
// Avoid implicitly captured closure
|
|
||||||
var libraryItems = string.IsNullOrEmpty(request.ParentId) && user != null ?
|
|
||||||
GetItemsConfiguredForLatest(user, filter) :
|
|
||||||
GetAllLibraryItems(request.UserId, _userManager, _libraryManager, request.ParentId, filter);
|
|
||||||
|
|
||||||
libraryItems = libraryItems.OrderByDescending(i => i.DateCreated);
|
|
||||||
|
|
||||||
if (request.IsPlayed.HasValue)
|
|
||||||
{
|
|
||||||
var takeLimit = (request.Limit ?? 20) * 20;
|
|
||||||
libraryItems = libraryItems.Take(takeLimit);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Avoid implicitly captured closure
|
|
||||||
var items = libraryItems
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
var list = new List<Tuple<BaseItem, List<BaseItem>>>();
|
var list = new List<Tuple<BaseItem, List<BaseItem>>>();
|
||||||
|
|
||||||
foreach (var item in items)
|
foreach (var item in libraryItems)
|
||||||
{
|
{
|
||||||
// Only grab the index container for media
|
// Only grab the index container for media
|
||||||
var container = item.IsFolder || !request.GroupItems ? null : item.LatestItemsIndexContainer;
|
var container = item.IsFolder || !request.GroupItems ? null : item.LatestItemsIndexContainer;
|
||||||
|
@ -318,59 +293,23 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IList<BaseItem> GetAllLibraryItems(string userId, IUserManager userManager, ILibraryManager libraryManager, string parentId, Func<BaseItem, bool> filter)
|
private IEnumerable<BaseItem> GetItemsForLatestItems(User user, string parentId, string[] includeItemTypes)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(parentId))
|
var parentIds = string.IsNullOrEmpty(parentId)
|
||||||
|
? new string[] { }
|
||||||
|
: new[] { parentId };
|
||||||
|
|
||||||
|
return _libraryManager.GetItems(new InternalItemsQuery(user)
|
||||||
{
|
{
|
||||||
var folder = (Folder)libraryManager.GetItemById(new Guid(parentId));
|
IncludeItemTypes = includeItemTypes,
|
||||||
|
SortOrder = SortOrder.Descending,
|
||||||
|
SortBy = new[] { ItemSortBy.DateCreated },
|
||||||
|
IsFolder = false,
|
||||||
|
ExcludeItemTypes = new[] { "ChannelItem", "Recording" },
|
||||||
|
ExcludeLocationTypes = new[] { LocationType.Virtual }
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(userId))
|
}, user, parentIds);
|
||||||
{
|
|
||||||
var user = userManager.GetUserById(userId);
|
|
||||||
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("User not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
return folder
|
|
||||||
.GetRecursiveChildren(user, filter)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
return folder
|
|
||||||
.GetRecursiveChildren(filter);
|
|
||||||
}
|
|
||||||
if (!string.IsNullOrWhiteSpace(userId))
|
|
||||||
{
|
|
||||||
var user = userManager.GetUserById(userId);
|
|
||||||
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("User not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
return user
|
|
||||||
.RootFolder
|
|
||||||
.GetRecursiveChildren(user, filter)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
return libraryManager
|
|
||||||
.RootFolder
|
|
||||||
.GetRecursiveChildren(filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerable<BaseItem> GetItemsConfiguredForLatest(User user, Func<BaseItem, bool> filter)
|
|
||||||
{
|
|
||||||
// Avoid implicitly captured closure
|
|
||||||
var currentUser = user;
|
|
||||||
|
|
||||||
return user.RootFolder.GetChildren(user, true)
|
|
||||||
.OfType<Folder>()
|
|
||||||
.Where(i => !user.Configuration.LatestItemsExcludes.Contains(i.Id.ToString("N")))
|
|
||||||
.SelectMany(i => i.GetRecursiveChildren(currentUser, filter))
|
|
||||||
.DistinctBy(i => i.Id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
public const int MigrationVersion = 1;
|
public const int MigrationVersion = 2;
|
||||||
|
|
||||||
public CleanDatabaseScheduledTask(ILibraryManager libraryManager, IItemRepository itemRepo, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem)
|
public CleanDatabaseScheduledTask(ILibraryManager libraryManager, IItemRepository itemRepo, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
|
|
|
@ -80,7 +80,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
private IDbCommand _deleteAncestorsCommand;
|
private IDbCommand _deleteAncestorsCommand;
|
||||||
private IDbCommand _saveAncestorCommand;
|
private IDbCommand _saveAncestorCommand;
|
||||||
|
|
||||||
private const int LatestSchemaVersion = 18;
|
private const int LatestSchemaVersion = 19;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
|
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
|
||||||
|
@ -213,6 +213,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
_connection.AddColumn(_logger, "TypedBaseItems", "Audio", "Text");
|
_connection.AddColumn(_logger, "TypedBaseItems", "Audio", "Text");
|
||||||
_connection.AddColumn(_logger, "TypedBaseItems", "ExternalServiceId", "Text");
|
_connection.AddColumn(_logger, "TypedBaseItems", "ExternalServiceId", "Text");
|
||||||
_connection.AddColumn(_logger, "TypedBaseItems", "Tags", "Text");
|
_connection.AddColumn(_logger, "TypedBaseItems", "Tags", "Text");
|
||||||
|
_connection.AddColumn(_logger, "TypedBaseItems", "IsFolder", "BIT");
|
||||||
|
|
||||||
PrepareStatements();
|
PrepareStatements();
|
||||||
|
|
||||||
|
@ -438,7 +439,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
"Studios",
|
"Studios",
|
||||||
"Audio",
|
"Audio",
|
||||||
"ExternalServiceId",
|
"ExternalServiceId",
|
||||||
"Tags"
|
"Tags",
|
||||||
|
"IsFolder"
|
||||||
};
|
};
|
||||||
_saveItemCommand = _connection.CreateCommand();
|
_saveItemCommand = _connection.CreateCommand();
|
||||||
_saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (";
|
_saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (";
|
||||||
|
@ -702,6 +704,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
}
|
}
|
||||||
|
|
||||||
_saveItemCommand.GetParameter(index++).Value = string.Join("|", item.Tags.ToArray());
|
_saveItemCommand.GetParameter(index++).Value = string.Join("|", item.Tags.ToArray());
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = item.IsFolder;
|
||||||
|
|
||||||
_saveItemCommand.Transaction = transaction;
|
_saveItemCommand.Transaction = transaction;
|
||||||
|
|
||||||
|
@ -1576,7 +1579,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
_logger.Debug(cmd.CommandText);
|
_logger.Debug(cmd.CommandText);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
|
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -1760,6 +1763,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
whereClauses.Add("IsSports=@IsSports");
|
whereClauses.Add("IsSports=@IsSports");
|
||||||
cmd.Parameters.Add(cmd, "@IsSports", DbType.Boolean).Value = query.IsSports;
|
cmd.Parameters.Add(cmd, "@IsSports", DbType.Boolean).Value = query.IsSports;
|
||||||
}
|
}
|
||||||
|
if (query.IsFolder.HasValue)
|
||||||
|
{
|
||||||
|
whereClauses.Add("IsFolder=@IsFolder");
|
||||||
|
cmd.Parameters.Add(cmd, "@IsFolder", DbType.Boolean).Value = query.IsFolder;
|
||||||
|
}
|
||||||
|
|
||||||
var includeTypes = query.IncludeItemTypes.SelectMany(MapIncludeItemTypes).ToArray();
|
var includeTypes = query.IncludeItemTypes.SelectMany(MapIncludeItemTypes).ToArray();
|
||||||
if (includeTypes.Length == 1)
|
if (includeTypes.Length == 1)
|
||||||
|
@ -1911,6 +1919,17 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
var inClause = string.Join(",", query.AncestorIds.Select(i => "'" + i + "'").ToArray());
|
var inClause = string.Join(",", query.AncestorIds.Select(i => "'" + i + "'").ToArray());
|
||||||
whereClauses.Add(string.Format("Guid in (select itemId from AncestorIds where AncestorId in ({0}))", inClause));
|
whereClauses.Add(string.Format("Guid in (select itemId from AncestorIds where AncestorId in ({0}))", inClause));
|
||||||
}
|
}
|
||||||
|
if (query.ExcludeLocationTypes.Length == 1)
|
||||||
|
{
|
||||||
|
whereClauses.Add("LocationType<>@LocationType");
|
||||||
|
cmd.Parameters.Add(cmd, "@LocationType", DbType.String).Value = query.ExcludeLocationTypes[0].ToString();
|
||||||
|
}
|
||||||
|
if (query.ExcludeLocationTypes.Length > 1)
|
||||||
|
{
|
||||||
|
var val = string.Join(",", query.ExcludeLocationTypes.Select(i => "'" + i + "'").ToArray());
|
||||||
|
|
||||||
|
whereClauses.Add("LocationType not in (" + val + ")");
|
||||||
|
}
|
||||||
|
|
||||||
if (addPaging)
|
if (addPaging)
|
||||||
{
|
{
|
||||||
|
@ -1976,6 +1995,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
dict[t.Name] = new[] { t.FullName };
|
dict[t.Name] = new[] { t.FullName };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dict["ChannelItem"] = new[] { typeof(ChannelVideoItem).FullName, typeof(ChannelAudioItem).FullName, typeof(ChannelFolderItem).FullName };
|
||||||
dict["Recording"] = new[] { typeof(LiveTvAudioRecording).FullName, typeof(LiveTvVideoRecording).FullName };
|
dict["Recording"] = new[] { typeof(LiveTvAudioRecording).FullName, typeof(LiveTvVideoRecording).FullName };
|
||||||
dict["Program"] = new[] { typeof(LiveTvProgram).FullName };
|
dict["Program"] = new[] { typeof(LiveTvProgram).FullName };
|
||||||
dict["TvChannel"] = new[] { typeof(LiveTvChannel).FullName };
|
dict["TvChannel"] = new[] { typeof(LiveTvChannel).FullName };
|
||||||
|
|
Loading…
Reference in New Issue
Block a user