Merge pull request #7006 from crobibero/base-item-kind-fixed

pull/7012/head
Bond-009 3 years ago committed by GitHub
commit b3c48e8e78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -62,7 +62,7 @@ namespace Emby.Server.Implementations.Data
private readonly ItemFields[] _allItemFields = Enum.GetValues<ItemFields>(); private readonly ItemFields[] _allItemFields = Enum.GetValues<ItemFields>();
private static readonly string[] _retriveItemColumns = private static readonly string[] _retrieveItemColumns =
{ {
"type", "type",
"data", "data",
@ -133,7 +133,7 @@ namespace Emby.Server.Implementations.Data
"OwnerId" "OwnerId"
}; };
private static readonly string _retriveItemColumnsSelectQuery = $"select {string.Join(',', _retriveItemColumns)} from TypedBaseItems where guid = @guid"; private static readonly string _retrieveItemColumnsSelectQuery = $"select {string.Join(',', _retrieveItemColumns)} from TypedBaseItems where guid = @guid";
private static readonly string[] _mediaStreamSaveColumns = private static readonly string[] _mediaStreamSaveColumns =
{ {
@ -284,6 +284,43 @@ namespace Emby.Server.Implementations.Data
private readonly Dictionary<string, string> _types = GetTypeMapDictionary(); private readonly Dictionary<string, string> _types = GetTypeMapDictionary();
private static readonly Dictionary<BaseItemKind, string> _baseItemKindNames = new()
{
{ BaseItemKind.AggregateFolder, typeof(AggregateFolder).FullName },
{ BaseItemKind.Audio, typeof(Audio).FullName },
{ BaseItemKind.AudioBook, typeof(AudioBook).FullName },
{ BaseItemKind.BasePluginFolder, typeof(BasePluginFolder).FullName },
{ BaseItemKind.Book, typeof(Book).FullName },
{ BaseItemKind.BoxSet, typeof(BoxSet).FullName },
{ BaseItemKind.Channel, typeof(Channel).FullName },
{ BaseItemKind.CollectionFolder, typeof(CollectionFolder).FullName },
{ BaseItemKind.Episode, typeof(Episode).FullName },
{ BaseItemKind.Folder, typeof(Folder).FullName },
{ BaseItemKind.Genre, typeof(Genre).FullName },
{ BaseItemKind.Movie, typeof(Movie).FullName },
{ BaseItemKind.LiveTvChannel, typeof(LiveTvChannel).FullName },
{ BaseItemKind.LiveTvProgram, typeof(LiveTvProgram).FullName },
{ BaseItemKind.MusicAlbum, typeof(MusicAlbum).FullName },
{ BaseItemKind.MusicArtist, typeof(MusicArtist).FullName },
{ BaseItemKind.MusicGenre, typeof(MusicGenre).FullName },
{ BaseItemKind.MusicVideo, typeof(MusicVideo).FullName },
{ BaseItemKind.Person, typeof(Person).FullName },
{ BaseItemKind.Photo, typeof(Photo).FullName },
{ BaseItemKind.PhotoAlbum, typeof(PhotoAlbum).FullName },
{ BaseItemKind.Playlist, typeof(Playlist).FullName },
{ BaseItemKind.PlaylistsFolder, typeof(PlaylistsFolder).FullName },
{ BaseItemKind.Season, typeof(Season).FullName },
{ BaseItemKind.Series, typeof(Series).FullName },
{ BaseItemKind.Studio, typeof(Studio).FullName },
{ BaseItemKind.Trailer, typeof(Trailer).FullName },
{ BaseItemKind.TvChannel, typeof(LiveTvChannel).FullName },
{ BaseItemKind.TvProgram, typeof(LiveTvProgram).FullName },
{ BaseItemKind.UserRootFolder, typeof(UserRootFolder).FullName },
{ BaseItemKind.UserView, typeof(UserView).FullName },
{ BaseItemKind.Video, typeof(Video).FullName },
{ BaseItemKind.Year, typeof(Year).FullName }
};
static SqliteItemRepository() static SqliteItemRepository()
{ {
var queryPrefixText = new StringBuilder(); var queryPrefixText = new StringBuilder();
@ -1319,7 +1356,7 @@ namespace Emby.Server.Implementations.Data
using (var connection = GetConnection(true)) using (var connection = GetConnection(true))
{ {
using (var statement = PrepareStatement(connection, _retriveItemColumnsSelectQuery)) using (var statement = PrepareStatement(connection, _retrieveItemColumnsSelectQuery))
{ {
statement.TryBind("@guid", id); statement.TryBind("@guid", id);
@ -2629,7 +2666,7 @@ namespace Emby.Server.Implementations.Data
query.Limit = query.Limit.Value + 4; query.Limit = query.Limit.Value + 4;
} }
var columns = _retriveItemColumns.ToList(); var columns = _retrieveItemColumns.ToList();
SetFinalColumnsToSelect(query, columns); SetFinalColumnsToSelect(query, columns);
var commandTextBuilder = new StringBuilder("select ", 1024) var commandTextBuilder = new StringBuilder("select ", 1024)
.AppendJoin(',', columns) .AppendJoin(',', columns)
@ -2820,7 +2857,7 @@ namespace Emby.Server.Implementations.Data
query.Limit = query.Limit.Value + 4; query.Limit = query.Limit.Value + 4;
} }
var columns = _retriveItemColumns.ToList(); var columns = _retrieveItemColumns.ToList();
SetFinalColumnsToSelect(query, columns); SetFinalColumnsToSelect(query, columns);
var commandTextBuilder = new StringBuilder("select ", 512) var commandTextBuilder = new StringBuilder("select ", 512)
.AppendJoin(',', columns) .AppendJoin(',', columns)
@ -3569,24 +3606,74 @@ namespace Emby.Server.Implementations.Data
var excludeTypes = query.ExcludeItemTypes; var excludeTypes = query.ExcludeItemTypes;
if (excludeTypes.Length == 1) if (excludeTypes.Length == 1)
{ {
whereClauses.Add("type<>@type"); if (_baseItemKindNames.TryGetValue(excludeTypes[0], out var excludeTypeName))
statement?.TryBind("@type", excludeTypes[0].ToString()); {
whereClauses.Add("type<>@type");
statement?.TryBind("@type", excludeTypeName);
}
else
{
Logger.LogWarning("Undefined BaseItemKind to Type mapping: {BaseItemKind}", excludeTypes[0]);
}
} }
else if (excludeTypes.Length > 1) else if (excludeTypes.Length > 1)
{ {
var inClause = string.Join(',', excludeTypes.Select(i => "'" + i + "'")); var whereBuilder = new StringBuilder("type not in (");
whereClauses.Add($"type not in ({inClause})"); foreach (var excludeType in excludeTypes)
{
if (_baseItemKindNames.TryGetValue(excludeType, out var baseItemKindName))
{
whereBuilder
.Append('\'')
.Append(baseItemKindName)
.Append("',");
}
else
{
Logger.LogWarning("Undefined BaseItemKind to Type mapping: {BaseItemKind}", excludeType);
}
}
// Remove trailing comma.
whereBuilder.Length--;
whereBuilder.Append(')');
whereClauses.Add(whereBuilder.ToString());
} }
} }
else if (includeTypes.Length == 1) else if (includeTypes.Length == 1)
{ {
whereClauses.Add("type=@type"); if (_baseItemKindNames.TryGetValue(includeTypes[0], out var includeTypeName))
statement?.TryBind("@type", includeTypes[0].ToString()); {
whereClauses.Add("type=@type");
statement?.TryBind("@type", includeTypeName);
}
else
{
Logger.LogWarning("Undefined BaseItemKind to Type mapping: {BaseItemKind}", includeTypes[0]);
}
} }
else if (includeTypes.Length > 1) else if (includeTypes.Length > 1)
{ {
var inClause = string.Join(',', includeTypes.Select(i => "'" + i + "'")); var whereBuilder = new StringBuilder("type in (");
whereClauses.Add($"type in ({inClause})"); foreach (var includeType in includeTypes)
{
if (_baseItemKindNames.TryGetValue(includeType, out var baseItemKindName))
{
whereBuilder
.Append('\'')
.Append(baseItemKindName)
.Append("',");
}
else
{
Logger.LogWarning("Undefined BaseItemKind to Type mapping: {BaseItemKind}", includeType);
}
}
// Remove trailing comma.
whereBuilder.Length--;
whereBuilder.Append(')');
whereClauses.Add(whereBuilder.ToString());
} }
if (query.ChannelIds.Count == 1) if (query.ChannelIds.Count == 1)
@ -5334,7 +5421,7 @@ AND Type = @InternalPersonType)");
stringBuilder.Clear(); stringBuilder.Clear();
} }
List<string> columns = _retriveItemColumns.ToList(); List<string> columns = _retrieveItemColumns.ToList();
// Unfortunately we need to add it to columns to ensure the order of the columns in the select // Unfortunately we need to add it to columns to ensure the order of the columns in the select
if (!string.IsNullOrEmpty(itemCountColumns)) if (!string.IsNullOrEmpty(itemCountColumns))
{ {

Loading…
Cancel
Save