The Free Software Media System - Server Backend & API
Clean up SqliteItemRepository
Bond_0098e7b15285ec8
diff --git a/Emby.Server.Implementations/Data/SqliteExtensions.cs b/Emby.Server.Implementations/Data/SqliteExtensions.csindex c87793072e..e7c5270b9f 100644--- a/Emby.Server.Implementations/Data/SqliteExtensions.cs+++ b/Emby.Server.Implementations/Data/SqliteExtensions.cs@@ -287,7 +287,7 @@ namespace Emby.Server.Implementations.Data}}- public static void TryBind(this IStatement statement, string name, byte[] value)+ public static void TryBind(this IStatement statement, string name, ReadOnlySpan<byte> value){if (statement.BindParameters.TryGetValue(name, out IBindParameter bindParam)){diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.csindex e3242f7b4f..d240b1e398 100644--- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs+++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs@@ -3315,7 +3315,7 @@ namespace Emby.Server.Implementations.Datafor (int i = 0; i < str.Length; i++){- if (!(char.IsLetter(str[i])) && (!(char.IsNumber(str[i]))))+ if (!char.IsLetter(str[i]) && (!char.IsNumber(str[i]))){return false;}@@ -3339,7 +3339,7 @@ namespace Emby.Server.Implementations.Datareturn IsAlphaNumeric(value);}- private List<string> GetWhereClauses(InternalItemsQuery query, IStatement statement, string paramSuffix = "")+ private List<string> GetWhereClauses(InternalItemsQuery query, IStatement statement){if (query.IsResumable ?? false){@@ -3351,27 +3351,27 @@ namespace Emby.Server.Implementations.Dataif (query.IsHD.HasValue){- var threshold = 1200;+ const int Threshold = 1200;if (query.IsHD.Value){- minWidth = threshold;+ minWidth = Threshold;}else{- maxWidth = threshold - 1;+ maxWidth = Threshold - 1;}}if (query.Is4K.HasValue){- var threshold = 3800;+ const int Threshold = 3800;if (query.Is4K.Value){- minWidth = threshold;+ minWidth = Threshold;}else{- maxWidth = threshold - 1;+ maxWidth = Threshold - 1;}}@@ -3380,93 +3380,61 @@ namespace Emby.Server.Implementations.Dataif (minWidth.HasValue){whereClauses.Add("Width>=@MinWidth");- if (statement != null)- {- statement.TryBind("@MinWidth", minWidth);- }+ statement?.TryBind("@MinWidth", minWidth);}+if (query.MinHeight.HasValue){whereClauses.Add("Height>=@MinHeight");- if (statement != null)- {- statement.TryBind("@MinHeight", query.MinHeight);- }+ statement?.TryBind("@MinHeight", query.MinHeight);}+if (maxWidth.HasValue){whereClauses.Add("Width<=@MaxWidth");- if (statement != null)- {- statement.TryBind("@MaxWidth", maxWidth);- }+ statement?.TryBind("@MaxWidth", maxWidth);}+if (query.MaxHeight.HasValue){whereClauses.Add("Height<=@MaxHeight");- if (statement != null)- {- statement.TryBind("@MaxHeight", query.MaxHeight);- }+ statement?.TryBind("@MaxHeight", query.MaxHeight);}if (query.IsLocked.HasValue){whereClauses.Add("IsLocked=@IsLocked");- if (statement != null)- {- statement.TryBind("@IsLocked", query.IsLocked);- }+ statement?.TryBind("@IsLocked", query.IsLocked);}var tags = query.Tags.ToList();var excludeTags = query.ExcludeTags.ToList();- if (query.IsMovie ?? false)+ if (query.IsMovie == true){- var alternateTypes = new List<string>();- if (query.IncludeItemTypes.Length == 0 || query.IncludeItemTypes.Contains(typeof(Movie).Name))- {- alternateTypes.Add(typeof(Movie).FullName);- }- if (query.IncludeItemTypes.Length == 0 || query.IncludeItemTypes.Contains(typeof(Trailer).Name))+ if (query.IncludeItemTypes.Length == 0+ || query.IncludeItemTypes.Contains(nameof(Movie))+ || query.IncludeItemTypes.Contains(nameof(Trailer))){- alternateTypes.Add(typeof(Trailer).FullName);- }-- var programAttribtues = new List<string>();- if (alternateTypes.Count == 0)- {- programAttribtues.Add("IsMovie=@IsMovie");+ whereClauses.Add("(IsMovie is null OR IsMovie=@IsMovie)");}else{- programAttribtues.Add("(IsMovie is null OR IsMovie=@IsMovie)");+ whereClauses.Add("IsMovie=@IsMovie");}- if (statement != null)- {- statement.TryBind("@IsMovie", true);- }-- whereClauses.Add("(" + string.Join(" OR ", programAttribtues) + ")");+ statement?.TryBind("@IsMovie", true);}else if (query.IsMovie.HasValue){whereClauses.Add("IsMovie=@IsMovie");- if (statement != null)- {- statement.TryBind("@IsMovie", query.IsMovie);- }+ statement?.TryBind("@IsMovie", query.IsMovie);}if (query.IsSeries.HasValue){whereClauses.Add("IsSeries=@IsSeries");- if (statement != null)- {- statement.TryBind("@IsSeries", query.IsSeries);- }+ statement?.TryBind("@IsSeries", query.IsSeries);}if (query.IsSports.HasValue)@@ -3518,10 +3486,7 @@ namespace Emby.Server.Implementations.Dataif (query.IsFolder.HasValue){whereClauses.Add("IsFolder=@IsFolder");- if (statement != null)- {- statement.TryBind("@IsFolder", query.IsFolder);- }+ statement?.TryBind("@IsFolder", query.IsFolder);}var includeTypes = query.IncludeItemTypes.SelectMany(MapIncludeItemTypes).ToArray();@@ -3532,10 +3497,7 @@ namespace Emby.Server.Implementations.Dataif (excludeTypes.Length == 1){whereClauses.Add("type<>@type");- if (statement != null)- {- statement.TryBind("@type", excludeTypes[0]);- }+ statement?.TryBind("@type", excludeTypes[0]);}else if (excludeTypes.Length > 1){@@ -3546,10 +3508,7 @@ namespace Emby.Server.Implementations.Dataelse if (includeTypes.Length == 1){whereClauses.Add("type=@type");- if (statement != null)- {- statement.TryBind("@type", includeTypes[0]);- }+ statement?.TryBind("@type", includeTypes[0]);}else if (includeTypes.Length > 1){@@ -3560,10 +3519,7 @@ namespace Emby.Server.Implementations.Dataif (query.ChannelIds.Length == 1){whereClauses.Add("ChannelId=@ChannelId");- if (statement != null)- {- statement.TryBind("@ChannelId", query.ChannelIds[0].ToString("N", CultureInfo.InvariantCulture));- }+ statement?.TryBind("@ChannelId", query.ChannelIds[0].ToString("N", CultureInfo.InvariantCulture));}else if (query.ChannelIds.Length > 1){@@ -3574,98 +3530,65 @@ namespace Emby.Server.Implementations.Dataif (!query.ParentId.Equals(Guid.Empty)){whereClauses.Add("ParentId=@ParentId");- if (statement != null)- {- statement.TryBind("@ParentId", query.ParentId);- }+ statement?.TryBind("@ParentId", query.ParentId);}if (!string.IsNullOrWhiteSpace(query.Path)){whereClauses.Add("Path=@Path");- if (statement != null)- {- statement.TryBind("@Path", GetPathToSave(query.Path));- }+ statement?.TryBind("@Path", GetPathToSave(query.Path));}if (!string.IsNullOrWhiteSpace(query.PresentationUniqueKey)){whereClauses.Add("PresentationUniqueKey=@PresentationUniqueKey");- if (statement != null)- {- statement.TryBind("@PresentationUniqueKey", query.PresentationUniqueKey);- }+ statement?.TryBind("@PresentationUniqueKey", query.PresentationUniqueKey);}if (query.MinCommunityRating.HasValue){whereClauses.Add("CommunityRating>=@MinCommunityRating");- if (statement != null)- {- statement.TryBind("@MinCommunityRating", query.MinCommunityRating.Value);- }+ statement?.TryBind("@MinCommunityRating", query.MinCommunityRating.Value);}if (query.MinIndexNumber.HasValue){whereClauses.Add("IndexNumber>=@MinIndexNumber");- if (statement != null)- {- statement.TryBind("@MinIndexNumber", query.MinIndexNumber.Value);- }+ statement?.TryBind("@MinIndexNumber", query.MinIndexNumber.Value);}if (query.MinDateCreated.HasValue){whereClauses.Add("DateCreated>=@MinDateCreated");- if (statement != null)- {- statement.TryBind("@MinDateCreated", query.MinDateCreated.Value);- }+ statement?.TryBind("@MinDateCreated", query.MinDateCreated.Value);}if (query.MinDateLastSaved.HasValue){whereClauses.Add("(DateLastSaved not null and DateLastSaved>=@MinDateLastSavedForUser)");- if (statement != null)- {- statement.TryBind("@MinDateLastSaved", query.MinDateLastSaved.Value);- }+ statement?.TryBind("@MinDateLastSaved", query.MinDateLastSaved.Value);}if (query.MinDateLastSavedForUser.HasValue){whereClauses.Add("(DateLastSaved not null and DateLastSaved>=@MinDateLastSavedForUser)");- if (statement != null)- {- statement.TryBind("@MinDateLastSavedForUser", query.MinDateLastSavedForUser.Value);- }+ statement?.TryBind("@MinDateLastSavedForUser", query.MinDateLastSavedForUser.Value);}if (query.IndexNumber.HasValue){whereClauses.Add("IndexNumber=@IndexNumber");- if (statement != null)- {- statement.TryBind("@IndexNumber", query.IndexNumber.Value);- }+ statement?.TryBind("@IndexNumber", query.IndexNumber.Value);}if (query.ParentIndexNumber.HasValue){whereClauses.Add("ParentIndexNumber=@ParentIndexNumber");- if (statement != null)- {- statement.TryBind("@ParentIndexNumber", query.ParentIndexNumber.Value);- }+ statement?.TryBind("@ParentIndexNumber", query.ParentIndexNumber.Value);}if (query.ParentIndexNumberNotEquals.HasValue){whereClauses.Add("(ParentIndexNumber<>@ParentIndexNumberNotEquals or ParentIndexNumber is null)");- if (statement != null)- {- statement.TryBind("@ParentIndexNumberNotEquals", query.ParentIndexNumberNotEquals.Value);- }+ statement?.TryBind("@ParentIndexNumberNotEquals", query.ParentIndexNumberNotEquals.Value);}var minEndDate = query.MinEndDate;@@ -3686,73 +3609,58 @@ namespace Emby.Server.Implementations.Dataif (minEndDate.HasValue){whereClauses.Add("EndDate>=@MinEndDate");- if (statement != null)- {- statement.TryBind("@MinEndDate", minEndDate.Value);- }+ statement?.TryBind("@MinEndDate", minEndDate.Value);}if (maxEndDate.HasValue){whereClauses.Add("EndDate<=@MaxEndDate");- if (statement != null)- {- statement.TryBind("@MaxEndDate", maxEndDate.Value);- }+ statement?.TryBind("@MaxEndDate", maxEndDate.Value);}if (query.MinStartDate.HasValue){whereClauses.Add("StartDate>=@MinStartDate");- if (statement != null)- {- statement.TryBind("@MinStartDate", query.MinStartDate.Value);- }+ statement?.TryBind("@MinStartDate", query.MinStartDate.Value);}if (query.MaxStartDate.HasValue){whereClauses.Add("StartDate<=@MaxStartDate");- if (statement != null)- {- statement.TryBind("@MaxStartDate", query.MaxStartDate.Value);- }+ statement?.TryBind("@MaxStartDate", query.MaxStartDate.Value);}if (query.MinPremiereDate.HasValue){whereClauses.Add("PremiereDate>=@MinPremiereDate");- if (statement != null)- {- statement.TryBind("@MinPremiereDate", query.MinPremiereDate.Value);- }+ statement?.TryBind("@MinPremiereDate", query.MinPremiereDate.Value);}+if (query.MaxPremiereDate.HasValue){whereClauses.Add("PremiereDate<=@MaxPremiereDate");- if (statement != null)- {- statement.TryBind("@MaxPremiereDate", query.MaxPremiereDate.Value);- }+ statement?.TryBind("@MaxPremiereDate", query.MaxPremiereDate.Value);}- if (query.TrailerTypes.Length > 0)+ var trailerTypes = query.TrailerTypes;+ int trailerTypesLen = trailerTypes.Length;+ if (trailerTypesLen > 0){- var clauses = new List<string>();- var index = 0;- foreach (var type in query.TrailerTypes)+ StringBuilder clause = new StringBuilder("(", trailerTypesLen * 32);+ for (int i = 0; i < trailerTypesLen; i++){- var paramName = "@TrailerTypes" + index;-- clauses.Add("TrailerTypes like " + paramName);- if (statement != null)- {- statement.TryBind(paramName, "%" + type + "%");- }- index++;+ var paramName = "@TrailerTypes" + i;+ clause.Append("TrailerTypes like ")+ .Append(paramName)+ .Append(" OR ");+ statement?.TryBind(paramName, "%" + trailerTypes[i] + "%");}- var clause = "(" + string.Join(" OR ", clauses) + ")";- whereClauses.Add(clause);++ // Remove last " OR "+ clause.Length -= 4;+ clause.Append(')');++ whereClauses.Add(clause.ToString());}if (query.IsAiring.HasValue)@@ -3760,24 +3668,15 @@ namespace Emby.Server.Implementations.Dataif (query.IsAiring.Value){whereClauses.Add("StartDate<=@MaxStartDate");- if (statement != null)- {- statement.TryBind("@MaxStartDate", DateTime.UtcNow);- }+ statement?.TryBind("@MaxStartDate", DateTime.UtcNow);whereClauses.Add("EndDate>=@MinEndDate");- if (statement != null)- {- statement.TryBind("@MinEndDate", DateTime.UtcNow);- }+ statement?.TryBind("@MinEndDate", DateTime.UtcNow);}else{whereClauses.Add("(StartDate>@IsAiringDate OR EndDate < @IsAiringDate)");- if (statement != null)- {- statement.TryBind("@IsAiringDate", DateTime.UtcNow);- }+ statement?.TryBind("@IsAiringDate", DateTime.UtcNow);}}@@ -3792,13 +3691,10 @@ namespace Emby.Server.Implementations.Datavar paramName = "@PersonId" + index;clauses.Add("(guid in (select itemid from People where Name = (select Name from TypedBaseItems where guid=" + paramName + ")))");-- if (statement != null)- {- statement.TryBind(paramName, personId.ToByteArray());- }+ statement?.TryBind(paramName, personId.ToByteArray());index++;}+var clause = "(" + string.Join(" OR ", clauses) + ")";whereClauses.Add(clause);}@@ -3806,47 +3702,31 @@ namespace Emby.Server.Implementations.Dataif (!string.IsNullOrWhiteSpace(query.Person)){whereClauses.Add("Guid in (select ItemId from People where Name=@PersonName)");- if (statement != null)- {- statement.TryBind("@PersonName", query.Person);- }+ statement?.TryBind("@PersonName", query.Person);}if (!string.IsNullOrWhiteSpace(query.MinSortName)){whereClauses.Add("SortName>=@MinSortName");- if (statement != null)- {- statement.TryBind("@MinSortName", query.MinSortName);- }+ statement?.TryBind("@MinSortName", query.MinSortName);}if (!string.IsNullOrWhiteSpace(query.ExternalSeriesId)){whereClauses.Add("ExternalSeriesId=@ExternalSeriesId");- if (statement != null)- {- statement.TryBind("@ExternalSeriesId", query.ExternalSeriesId);- }+ statement?.TryBind("@ExternalSeriesId", query.ExternalSeriesId);}if (!string.IsNullOrWhiteSpace(query.ExternalId)){whereClauses.Add("ExternalId=@ExternalId");- if (statement != null)- {- statement.TryBind("@ExternalId", query.ExternalId);- }+ statement?.TryBind("@ExternalId", query.ExternalId);}if (!string.IsNullOrWhiteSpace(query.Name)){whereClauses.Add("CleanName=@Name");-- if (statement != null)- {- statement.TryBind("@Name", GetCleanValue(query.Name));- }+ statement?.TryBind("@Name", GetCleanValue(query.Name));}// These are the same, for now@@ -3865,28 +3745,21 @@ namespace Emby.Server.Implementations.Dataif (!string.IsNullOrWhiteSpace(query.NameStartsWith)){whereClauses.Add("SortName like @NameStartsWith");- if (statement != null)- {- statement.TryBind("@NameStartsWith", query.NameStartsWith + "%");- }+ statement?.TryBind("@NameStartsWith", query.NameStartsWith + "%");}+if (!string.IsNullOrWhiteSpace(query.NameStartsWithOrGreater)){whereClauses.Add("SortName >= @NameStartsWithOrGreater");// lowercase this because SortName is stored as lowercase- if (statement != null)- {- statement.TryBind("@NameStartsWithOrGreater", query.NameStartsWithOrGreater.ToLowerInvariant());- }+ statement?.TryBind("@NameStartsWithOrGreater", query.NameStartsWithOrGreater.ToLowerInvariant());}+if (!string.IsNullOrWhiteSpace(query.NameLessThan)){whereClauses.Add("SortName < @NameLessThan");// lowercase this because SortName is stored as lowercase- if (statement != null)- {- statement.TryBind("@NameLessThan", query.NameLessThan.ToLowerInvariant());- }+ statement?.TryBind("@NameLessThan", query.NameLessThan.ToLowerInvariant());}if (query.ImageTypes.Length > 0)@@ -3902,18 +3775,12 @@ namespace Emby.Server.Implementations.Dataif (query.IsLiked.Value){whereClauses.Add("rating>=@UserRating");- if (statement != null)- {- statement.TryBind("@UserRating", UserItemData.MinLikeValue);- }+ statement?.TryBind("@UserRating", UserItemData.MinLikeValue);}else{whereClauses.Add("(rating is null or rating<@UserRating)");- if (statement != null)- {- statement.TryBind("@UserRating", UserItemData.MinLikeValue);- }+ statement?.TryBind("@UserRating", UserItemData.MinLikeValue);}}@@ -3927,10 +3794,8 @@ namespace Emby.Server.Implementations.Data{whereClauses.Add("(IsFavorite is null or IsFavorite=@IsFavoriteOrLiked)");}- if (statement != null)- {- statement.TryBind("@IsFavoriteOrLiked", query.IsFavoriteOrLiked.Value);- }++ statement?.TryBind("@IsFavoriteOrLiked", query.IsFavoriteOrLiked.Value);}if (query.IsFavorite.HasValue)@@ -3943,10 +3808,8 @@ namespace Emby.Server.Implementations.Data{whereClauses.Add("(IsFavorite is null or IsFavorite=@IsFavorite)");}- if (statement != null)- {- statement.TryBind("@IsFavorite", query.IsFavorite.Value);- }++ statement?.TryBind("@IsFavorite", query.IsFavorite.Value);}if (EnableJoinUserData(query))@@ -3975,10 +3838,8 @@ namespace Emby.Server.Implementations.Data{whereClauses.Add("(played is null or played=@IsPlayed)");}- if (statement != null)- {- statement.TryBind("@IsPlayed", query.IsPlayed.Value);- }++ statement?.TryBind("@IsPlayed", query.IsPlayed.Value);}}}@@ -4010,6 +3871,7 @@ namespace Emby.Server.Implementations.Data}index++;}+var clause = "(" + string.Join(" OR ", clauses) + ")";whereClauses.Add(clause);}@@ -4029,6 +3891,7 @@ namespace Emby.Server.Implementations.Data}index++;}+var clause = "(" + string.Join(" OR ", clauses) + ")";whereClauses.Add(clause);}@@ -4762,18 +4625,22 @@ namespace Emby.Server.Implementations.Data{list.Add(typeof(Person).Name);}+if (IsTypeInQuery(typeof(Genre).Name, query)){list.Add(typeof(Genre).Name);}+if (IsTypeInQuery(typeof(MusicGenre).Name, query)){list.Add(typeof(MusicGenre).Name);}+if (IsTypeInQuery(typeof(MusicArtist).Name, query)){list.Add(typeof(MusicArtist).Name);}+if (IsTypeInQuery(typeof(Studio).Name, query)){list.Add(typeof(Studio).Name);@@ -4847,7 +4714,7 @@ namespace Emby.Server.Implementations.Datareturn false;}- private static readonly Type[] KnownTypes =+ private static readonly Type[] _knownTypes ={typeof(LiveTvProgram),typeof(LiveTvChannel),@@ -4916,7 +4783,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type{var dict = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);- foreach (var t in KnownTypes)+ foreach (var t in _knownTypes){dict[t.Name] = new[] { t.FullName };}@@ -4928,7 +4795,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type}// Not crazy about having this all the way down here, but at least it's in one place- readonly Dictionary<string, string[]> _types = GetTypeMapDictionary();+ private readonly Dictionary<string, string[]> _types = GetTypeMapDictionary();private string[] MapIncludeItemTypes(string value){@@ -4945,7 +4812,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Typereturn Array.Empty<string>();}- public void DeleteItem(Guid id, CancellationToken cancellationToken)+ public void DeleteItem(Guid id){if (id == Guid.Empty){@@ -4981,7 +4848,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type}}- private void ExecuteWithSingleParam(IDatabaseConnection db, string query, byte[] value)+ private void ExecuteWithSingleParam(IDatabaseConnection db, string query, ReadOnlySpan<byte> value){using (var statement = PrepareStatement(db, query)){@@ -5531,6 +5398,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type{GetWhereClauses(typeSubQuery, null);}+BindSimilarParams(query, statement);BindSearchParams(query, statement);GetWhereClauses(innerQuery, statement);@@ -5572,7 +5440,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type}var allTypes = typeString.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)- .ToLookup(i => i);+ .ToLookup(x => x);foreach (var type in allTypes){@@ -5663,30 +5531,26 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Typeprivate void InsertItemValues(byte[] idBlob, List<(int, string)> values, IDatabaseConnection db){+ const int Limit = 100;var startIndex = 0;- var limit = 100;while (startIndex < values.Count){var insertText = new StringBuilder("insert into ItemValues (ItemId, Type, Value, CleanValue) values ");- var endIndex = Math.Min(values.Count, startIndex + limit);- var isSubsequentRow = false;+ var endIndex = Math.Min(values.Count, startIndex + Limit);for (var i = startIndex; i < endIndex; i++){- if (isSubsequentRow)- {- insertText.Append(',');- }-insertText.AppendFormat(CultureInfo.InvariantCulture,- "(@ItemId, @Type{0}, @Value{0}, @CleanValue{0})",+ "(@ItemId, @Type{0}, @Value{0}, @CleanValue{0}),",i);- isSubsequentRow = true;}+ // Remove last comma+ insertText.Length--;+using (var statement = PrepareStatement(db, insertText.ToString())){statement.TryBind("@ItemId", idBlob);@@ -5714,7 +5578,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Typestatement.MoveNext();}- startIndex += limit;+ startIndex += Limit;}}@@ -5749,28 +5613,23 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Typeprivate void InsertPeople(byte[] idBlob, List<PersonInfo> people, IDatabaseConnection db){+ const int Limit = 100;var startIndex = 0;- var limit = 100;var listIndex = 0;while (startIndex < people.Count){var insertText = new StringBuilder("insert into People (ItemId, Name, Role, PersonType, SortOrder, ListOrder) values ");- var endIndex = Math.Min(people.Count, startIndex + limit);- var isSubsequentRow = false;-+ var endIndex = Math.Min(people.Count, startIndex + Limit);for (var i = startIndex; i < endIndex; i++){- if (isSubsequentRow)- {- insertText.Append(',');- }-- insertText.AppendFormat("(@ItemId, @Name{0}, @Role{0}, @PersonType{0}, @SortOrder{0}, @ListOrder{0})", i.ToString(CultureInfo.InvariantCulture));- isSubsequentRow = true;+ insertText.AppendFormat("(@ItemId, @Name{0}, @Role{0}, @PersonType{0}, @SortOrder{0}, @ListOrder{0}),", i.ToString(CultureInfo.InvariantCulture));}+ // Remove last comma+ insertText.Length--;+using (var statement = PrepareStatement(db, insertText.ToString())){statement.TryBind("@ItemId", idBlob);@@ -5794,16 +5653,17 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Typestatement.MoveNext();}- startIndex += limit;+ startIndex += Limit;}}private PersonInfo GetPerson(IReadOnlyList<IResultSetValue> reader){- var item = new PersonInfo();-- item.ItemId = reader.GetGuid(0);- item.Name = reader.GetString(1);+ var item = new PersonInfo+ {+ ItemId = reader.GetGuid(0),+ Name = reader.GetString(1)+ };if (!reader.IsDBNull(2)){@@ -5910,20 +5770,28 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Typeprivate void InsertMediaStreams(byte[] idBlob, List<MediaStream> streams, IDatabaseConnection db){+ const int Limit = 10;var startIndex = 0;- var limit = 10;while (startIndex < streams.Count){- var insertText = new StringBuilder(string.Format("insert into mediastreams ({0}) values ", string.Join(",", _mediaStreamSaveColumns)));+ var insertText = new StringBuilder("insert into mediastreams (");+ foreach (var column in _mediaStreamSaveColumns)+ {+ insertText.Append(column).Append(',');+ }- var endIndex = Math.Min(streams.Count, startIndex + limit);+ // Remove last comma+ insertText.Length--;+ insertText.Append(") values ");++ var endIndex = Math.Min(streams.Count, startIndex + Limit);for (var i = startIndex; i < endIndex; i++){if (i != startIndex){- insertText.Append(",");+ insertText.Append(',');}var index = i.ToString(CultureInfo.InvariantCulture);@@ -5931,11 +5799,12 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Typeforeach (var column in _mediaStreamSaveColumns.Skip(1)){- insertText.Append("@" + column + index + ",");+ insertText.Append('@').Append(column).Append(index).Append(',');}+insertText.Length -= 1; // Remove the last comma- insertText.Append(")");+ insertText.Append(')');}using (var statement = PrepareStatement(db, insertText.ToString()))@@ -5997,7 +5866,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Typestatement.MoveNext();}- startIndex += limit;+ startIndex += Limit;}}@@ -6014,7 +5883,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.TypeIndex = reader[1].ToInt()};- item.Type = (MediaStreamType)Enum.Parse(typeof(MediaStreamType), reader[2].ToString(), true);+ item.Type = Enum.Parse<MediaStreamType>(reader[2].ToString(), true);if (reader[3].SQLiteType != SQLiteType.Null){diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.csindex 8ec4d08be5..73378cb1e1 100644--- a/Emby.Server.Implementations/Library/LibraryManager.cs+++ b/Emby.Server.Implementations/Library/LibraryManager.cs@@ -437,10 +437,10 @@ namespace Emby.Server.Implementations.Libraryitem.SetParent(null);- ItemRepository.DeleteItem(item.Id, CancellationToken.None);+ ItemRepository.DeleteItem(item.Id);foreach (var child in children){- ItemRepository.DeleteItem(child.Id, CancellationToken.None);+ ItemRepository.DeleteItem(child.Id);}_libraryItemsCache.TryRemove(item.Id, out BaseItem removed);diff --git a/MediaBrowser.Controller/Persistence/IItemRepository.cs b/MediaBrowser.Controller/Persistence/IItemRepository.csindex eb5a8ded84..3bce79d8ac 100644--- a/MediaBrowser.Controller/Persistence/IItemRepository.cs+++ b/MediaBrowser.Controller/Persistence/IItemRepository.cs@@ -25,7 +25,7 @@ namespace MediaBrowser.Controller.Persistence/// </summary>/// <param name="id">The identifier.</param>/// <param name="cancellationToken">The cancellation token.</param>- void DeleteItem(Guid id, CancellationToken cancellationToken);+ void DeleteItem(Guid id);/// <summary>/// Saves the items.