mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-05-30 19:55:08 -04:00
update querying
This commit is contained in:
parent
743102b88f
commit
f6e73a428e
@ -1939,6 +1939,36 @@ namespace MediaBrowser.Controller.Entities
|
|||||||
return GetParents().Select(i => i.Id).Concat(LibraryManager.GetCollectionFolders(this).Select(i => i.Id));
|
return GetParents().Select(i => i.Id).Concat(LibraryManager.GetCollectionFolders(this).Select(i => i.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BaseItem GetTopParent()
|
||||||
|
{
|
||||||
|
if (IsTopParent)
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetParents().FirstOrDefault(i => i.IsTopParent);
|
||||||
|
}
|
||||||
|
|
||||||
|
[IgnoreDataMember]
|
||||||
|
public virtual bool IsTopParent
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (GetParent() is AggregateFolder || this is Channel || this is BasePluginFolder)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var view = this as UserView;
|
||||||
|
if (view != null && string.Equals(view.ViewType, CollectionType.LiveTv, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[IgnoreDataMember]
|
[IgnoreDataMember]
|
||||||
public virtual bool SupportsAncestors
|
public virtual bool SupportsAncestors
|
||||||
{
|
{
|
||||||
|
@ -181,9 +181,7 @@ namespace MediaBrowser.Controller.Entities
|
|||||||
}
|
}
|
||||||
private List<LinkedChild> GetLinkedChildrenInternal()
|
private List<LinkedChild> GetLinkedChildrenInternal()
|
||||||
{
|
{
|
||||||
return LibraryManager.RootFolder.Children
|
return GetPhysicalParents()
|
||||||
.OfType<Folder>()
|
|
||||||
.Where(i => i.Path != null && PhysicalLocations.Contains(i.Path, StringComparer.OrdinalIgnoreCase))
|
|
||||||
.SelectMany(c => c.LinkedChildren)
|
.SelectMany(c => c.LinkedChildren)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
@ -199,11 +197,14 @@ namespace MediaBrowser.Controller.Entities
|
|||||||
|
|
||||||
private IEnumerable<BaseItem> GetActualChildren()
|
private IEnumerable<BaseItem> GetActualChildren()
|
||||||
{
|
{
|
||||||
return
|
return GetPhysicalParents().SelectMany(c => c.Children);
|
||||||
LibraryManager.RootFolder.Children
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Folder> GetPhysicalParents()
|
||||||
|
{
|
||||||
|
return LibraryManager.RootFolder.Children
|
||||||
.OfType<Folder>()
|
.OfType<Folder>()
|
||||||
.Where(i => i.Path != null && PhysicalLocations.Contains(i.Path, StringComparer.OrdinalIgnoreCase))
|
.Where(i => i.Path != null && PhysicalLocations.Contains(i.Path, StringComparer.OrdinalIgnoreCase));
|
||||||
.SelectMany(c => c.Children);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[IgnoreDataMember]
|
[IgnoreDataMember]
|
||||||
|
@ -107,6 +107,7 @@ 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 string[] TopParentIds { get; set; }
|
||||||
|
|
||||||
public LocationType[] ExcludeLocationTypes { get; set; }
|
public LocationType[] ExcludeLocationTypes { get; set; }
|
||||||
|
|
||||||
@ -131,6 +132,7 @@ namespace MediaBrowser.Controller.Entities
|
|||||||
ChannelIds = new string[] { };
|
ChannelIds = new string[] { };
|
||||||
ItemIds = new string[] { };
|
ItemIds = new string[] { };
|
||||||
AncestorIds = new string[] { };
|
AncestorIds = new string[] { };
|
||||||
|
TopParentIds = new string[] { };
|
||||||
ExcludeLocationTypes = new LocationType[] { };
|
ExcludeLocationTypes = new LocationType[] { };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,8 @@ namespace MediaBrowser.Controller.Entities
|
|||||||
{
|
{
|
||||||
CollectionType.Games,
|
CollectionType.Games,
|
||||||
CollectionType.Books,
|
CollectionType.Books,
|
||||||
CollectionType.MusicVideos
|
CollectionType.MusicVideos ,
|
||||||
|
CollectionType.HomeVideos
|
||||||
};
|
};
|
||||||
|
|
||||||
return types.Contains(viewType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
|
return types.Contains(viewType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
|
||||||
|
@ -1336,16 +1336,16 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||||||
|
|
||||||
private void AddUserToQuery(InternalItemsQuery query, User user)
|
private void AddUserToQuery(InternalItemsQuery query, User user)
|
||||||
{
|
{
|
||||||
if (query.AncestorIds.Length == 0 && !query.ParentId.HasValue && query.ChannelIds.Length == 0)
|
if (query.AncestorIds.Length == 0 && !query.ParentId.HasValue && query.ChannelIds.Length == 0 && query.TopParentIds.Length == 0)
|
||||||
{
|
{
|
||||||
//var userViews = _userviewManager().GetUserViews(new UserViewQuery
|
var userViews = _userviewManager().GetUserViews(new UserViewQuery
|
||||||
//{
|
{
|
||||||
// UserId = user.Id.ToString("N"),
|
UserId = user.Id.ToString("N"),
|
||||||
// IncludeHidden = true
|
IncludeHidden = true
|
||||||
|
|
||||||
//}, CancellationToken.None).Result.ToList();
|
}, CancellationToken.None).Result.ToList();
|
||||||
|
|
||||||
//query.AncestorIds = userViews.SelectMany(i => i.GetIdsForAncestorQuery()).Distinct().Select(i => i.ToString("N")).ToArray();
|
query.TopParentIds = userViews.SelectMany(GetTopParentsForQuery).Select(i => i.Id.ToString("N")).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: handle blocking by tags
|
// TODO: handle blocking by tags
|
||||||
@ -1358,6 +1358,60 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<BaseItem> GetTopParentsForQuery(BaseItem item)
|
||||||
|
{
|
||||||
|
var view = item as UserView;
|
||||||
|
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
if (string.Equals(view.ViewType, CollectionType.LiveTv))
|
||||||
|
{
|
||||||
|
return new[] { view };
|
||||||
|
}
|
||||||
|
if (string.Equals(view.ViewType, CollectionType.Channels))
|
||||||
|
{
|
||||||
|
// TODO: Return channels
|
||||||
|
return new[] { view };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Translate view into folders
|
||||||
|
if (view.DisplayParentId != Guid.Empty)
|
||||||
|
{
|
||||||
|
var displayParent = GetItemById(view.DisplayParentId);
|
||||||
|
if (displayParent != null)
|
||||||
|
{
|
||||||
|
return GetTopParentsForQuery(displayParent);
|
||||||
|
}
|
||||||
|
return new BaseItem[] { };
|
||||||
|
}
|
||||||
|
if (view.ParentId != Guid.Empty)
|
||||||
|
{
|
||||||
|
var displayParent = GetItemById(view.ParentId);
|
||||||
|
if (displayParent != null)
|
||||||
|
{
|
||||||
|
return GetTopParentsForQuery(displayParent);
|
||||||
|
}
|
||||||
|
return new BaseItem[] { };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle grouping
|
||||||
|
return new BaseItem[] { };
|
||||||
|
}
|
||||||
|
|
||||||
|
var collectionFolder = item as CollectionFolder;
|
||||||
|
if (collectionFolder != null)
|
||||||
|
{
|
||||||
|
return collectionFolder.GetPhysicalParents();
|
||||||
|
}
|
||||||
|
|
||||||
|
var topParent = item.GetTopParent();
|
||||||
|
if (topParent != null)
|
||||||
|
{
|
||||||
|
return new[] { topParent };
|
||||||
|
}
|
||||||
|
return new BaseItem[] { };
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the intros.
|
/// Gets the intros.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -1726,16 +1780,16 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||||||
|
|
||||||
private string GetTopFolderContentType(BaseItem item)
|
private string GetTopFolderContentType(BaseItem item)
|
||||||
{
|
{
|
||||||
while (!(item.GetParent() is AggregateFolder) && item.GetParent() != null)
|
|
||||||
{
|
|
||||||
item = item.GetParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item == null)
|
if (item == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (!(item.GetParent() is AggregateFolder) && item.GetParent() != null)
|
||||||
|
{
|
||||||
|
item = item.GetParent();
|
||||||
|
}
|
||||||
|
|
||||||
return GetUserRootFolder().Children
|
return GetUserRootFolder().Children
|
||||||
.OfType<ICollectionFolder>()
|
.OfType<ICollectionFolder>()
|
||||||
.Where(i => string.Equals(i.Path, item.Path, StringComparison.OrdinalIgnoreCase) || i.PhysicalLocations.Contains(item.Path))
|
.Where(i => string.Equals(i.Path, item.Path, StringComparison.OrdinalIgnoreCase) || i.PhysicalLocations.Contains(item.Path))
|
||||||
|
@ -25,7 +25,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 = 4;
|
public const int MigrationVersion = 6;
|
||||||
|
|
||||||
public CleanDatabaseScheduledTask(ILibraryManager libraryManager, IItemRepository itemRepo, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem)
|
public CleanDatabaseScheduledTask(ILibraryManager libraryManager, IItemRepository itemRepo, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
|
@ -82,7 +82,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||||||
|
|
||||||
private IDbCommand _updateInheritedRatingCommand;
|
private IDbCommand _updateInheritedRatingCommand;
|
||||||
|
|
||||||
private const int LatestSchemaVersion = 32;
|
private const int LatestSchemaVersion = 37;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
|
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
|
||||||
@ -223,6 +223,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||||||
_connection.AddColumn(_logger, "TypedBaseItems", "IsFolder", "BIT");
|
_connection.AddColumn(_logger, "TypedBaseItems", "IsFolder", "BIT");
|
||||||
_connection.AddColumn(_logger, "TypedBaseItems", "InheritedParentalRatingValue", "INT");
|
_connection.AddColumn(_logger, "TypedBaseItems", "InheritedParentalRatingValue", "INT");
|
||||||
_connection.AddColumn(_logger, "TypedBaseItems", "UnratedType", "Text");
|
_connection.AddColumn(_logger, "TypedBaseItems", "UnratedType", "Text");
|
||||||
|
_connection.AddColumn(_logger, "TypedBaseItems", "TopParentId", "Text");
|
||||||
|
|
||||||
PrepareStatements();
|
PrepareStatements();
|
||||||
|
|
||||||
@ -451,7 +452,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||||||
"ExternalServiceId",
|
"ExternalServiceId",
|
||||||
"Tags",
|
"Tags",
|
||||||
"IsFolder",
|
"IsFolder",
|
||||||
"UnratedType"
|
"UnratedType",
|
||||||
|
"TopParentId"
|
||||||
};
|
};
|
||||||
_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 (";
|
||||||
@ -725,7 +727,17 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||||||
_saveItemCommand.GetParameter(index++).Value = item.IsFolder;
|
_saveItemCommand.GetParameter(index++).Value = item.IsFolder;
|
||||||
|
|
||||||
_saveItemCommand.GetParameter(index++).Value = item.GetBlockUnratedType().ToString();
|
_saveItemCommand.GetParameter(index++).Value = item.GetBlockUnratedType().ToString();
|
||||||
|
|
||||||
|
var topParent = item.GetTopParent();
|
||||||
|
if (topParent != null)
|
||||||
|
{
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = topParent.Id.ToString("N");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = null;
|
||||||
|
}
|
||||||
|
|
||||||
_saveItemCommand.Transaction = transaction;
|
_saveItemCommand.Transaction = transaction;
|
||||||
|
|
||||||
_saveItemCommand.ExecuteNonQuery();
|
_saveItemCommand.ExecuteNonQuery();
|
||||||
@ -1940,6 +1952,18 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||||||
whereClauses.Add("LocationType not in (" + val + ")");
|
whereClauses.Add("LocationType not in (" + val + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (query.TopParentIds.Length == 1)
|
||||||
|
{
|
||||||
|
whereClauses.Add("(TopParentId is null or TopParentId=@TopParentId)");
|
||||||
|
cmd.Parameters.Add(cmd, "@TopParentId", DbType.String).Value = query.TopParentIds[0];
|
||||||
|
}
|
||||||
|
if (query.TopParentIds.Length > 1)
|
||||||
|
{
|
||||||
|
var val = string.Join(",", query.TopParentIds.Select(i => "'" + i + "'").ToArray());
|
||||||
|
|
||||||
|
whereClauses.Add("(TopParentId is null or TopParentId in (" + val + "))");
|
||||||
|
}
|
||||||
|
|
||||||
if (query.AncestorIds.Length == 1)
|
if (query.AncestorIds.Length == 1)
|
||||||
{
|
{
|
||||||
whereClauses.Add("Guid in (select itemId from AncestorIds where AncestorId=@AncestorId)");
|
whereClauses.Add("Guid in (select itemId from AncestorIds where AncestorId=@AncestorId)");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user