diff options
| author | Claus Vium <cvium@users.noreply.github.com> | 2022-03-11 08:15:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-11 08:15:12 +0100 |
| commit | 53209830e7b566949c16b43c864f6f85336cb92c (patch) | |
| tree | 59a99d347cffe722da175269dfd99bac08fb7fb0 /Emby.Server.Implementations/Library | |
| parent | 21ef6661d6ef48fb18da10b8e0abf2c1d1345ed1 (diff) | |
| parent | f50a250cd9fac47bcbd9a05e99c8ffe4d294e320 (diff) | |
Merge pull request #7346 from Bond-009/guid
Optimize Guid comparisons
Diffstat (limited to 'Emby.Server.Implementations/Library')
5 files changed, 32 insertions, 28 deletions
diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index 0770bdbc3..a9428ae9b 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -756,7 +756,7 @@ namespace Emby.Server.Implementations.Library Path = path }; - if (folder.Id.Equals(Guid.Empty)) + if (folder.Id.Equals(default)) { if (string.IsNullOrEmpty(folder.Path)) { @@ -775,7 +775,7 @@ namespace Emby.Server.Implementations.Library folder = dbItem; } - if (folder.ParentId != rootFolder.Id) + if (!folder.ParentId.Equals(rootFolder.Id)) { folder.ParentId = rootFolder.Id; folder.UpdateToRepositoryAsync(ItemUpdateType.MetadataImport, CancellationToken.None).GetAwaiter().GetResult(); @@ -1253,7 +1253,7 @@ namespace Emby.Server.Implementations.Library /// <exception cref="ArgumentNullException"><paramref name="id"/> is <c>null</c>.</exception> public BaseItem GetItemById(Guid id) { - if (id == Guid.Empty) + if (id.Equals(default)) { throw new ArgumentException("Guid can't be empty", nameof(id)); } @@ -1275,7 +1275,7 @@ namespace Emby.Server.Implementations.Library public List<BaseItem> GetItemList(InternalItemsQuery query, bool allowExternalContent) { - if (query.Recursive && query.ParentId != Guid.Empty) + if (query.Recursive && !query.ParentId.Equals(default)) { var parent = GetItemById(query.ParentId); if (parent != null) @@ -1299,7 +1299,7 @@ namespace Emby.Server.Implementations.Library public int GetCount(InternalItemsQuery query) { - if (query.Recursive && !query.ParentId.Equals(Guid.Empty)) + if (query.Recursive && !query.ParentId.Equals(default)) { var parent = GetItemById(query.ParentId); if (parent != null) @@ -1457,7 +1457,7 @@ namespace Emby.Server.Implementations.Library public QueryResult<BaseItem> GetItemsResult(InternalItemsQuery query) { - if (query.Recursive && !query.ParentId.Equals(Guid.Empty)) + if (query.Recursive && !query.ParentId.Equals(default)) { var parent = GetItemById(query.ParentId); if (parent != null) @@ -1513,7 +1513,7 @@ namespace Emby.Server.Implementations.Library private void AddUserToQuery(InternalItemsQuery query, User user, bool allowExternalContent = true) { if (query.AncestorIds.Length == 0 && - query.ParentId.Equals(Guid.Empty) && + query.ParentId.Equals(default) && query.ChannelIds.Count == 0 && query.TopParentIds.Length == 0 && string.IsNullOrEmpty(query.AncestorWithPresentationUniqueKey) && @@ -1541,7 +1541,7 @@ namespace Emby.Server.Implementations.Library } // Translate view into folders - if (!view.DisplayParentId.Equals(Guid.Empty)) + if (!view.DisplayParentId.Equals(default)) { var displayParent = GetItemById(view.DisplayParentId); if (displayParent != null) @@ -1552,7 +1552,7 @@ namespace Emby.Server.Implementations.Library return Array.Empty<Guid>(); } - if (!view.ParentId.Equals(Guid.Empty)) + if (!view.ParentId.Equals(default)) { var displayParent = GetItemById(view.ParentId); if (displayParent != null) @@ -2154,7 +2154,7 @@ namespace Emby.Server.Implementations.Library return null; } - while (!item.ParentId.Equals(Guid.Empty)) + while (!item.ParentId.Equals(default)) { var parent = item.GetParent(); if (parent == null || parent is AggregateFolder) @@ -2232,7 +2232,9 @@ namespace Emby.Server.Implementations.Library string viewType, string sortName) { - var parentIdString = parentId.Equals(Guid.Empty) ? null : parentId.ToString("N", CultureInfo.InvariantCulture); + var parentIdString = parentId.Equals(default) + ? null + : parentId.ToString("N", CultureInfo.InvariantCulture); var idValues = "38_namedview_" + name + user.Id.ToString("N", CultureInfo.InvariantCulture) + (parentIdString ?? string.Empty) + (viewType ?? string.Empty); var id = GetNewItemId(idValues, typeof(UserView)); @@ -2266,7 +2268,7 @@ namespace Emby.Server.Implementations.Library var refresh = isNew || DateTime.UtcNow - item.DateLastRefreshed >= _viewRefreshInterval; - if (!refresh && !item.DisplayParentId.Equals(Guid.Empty)) + if (!refresh && !item.DisplayParentId.Equals(default)) { var displayParent = GetItemById(item.DisplayParentId); refresh = displayParent != null && displayParent.DateLastSaved > item.DateLastRefreshed; @@ -2333,7 +2335,7 @@ namespace Emby.Server.Implementations.Library var refresh = isNew || DateTime.UtcNow - item.DateLastRefreshed >= _viewRefreshInterval; - if (!refresh && !item.DisplayParentId.Equals(Guid.Empty)) + if (!refresh && !item.DisplayParentId.Equals(default)) { var displayParent = GetItemById(item.DisplayParentId); refresh = displayParent != null && displayParent.DateLastSaved > item.DateLastRefreshed; @@ -2366,7 +2368,9 @@ namespace Emby.Server.Implementations.Library throw new ArgumentNullException(nameof(name)); } - var parentIdString = parentId.Equals(Guid.Empty) ? null : parentId.ToString("N", CultureInfo.InvariantCulture); + var parentIdString = parentId.Equals(default) + ? null + : parentId.ToString("N", CultureInfo.InvariantCulture); var idValues = "37_namedview_" + name + (parentIdString ?? string.Empty) + (viewType ?? string.Empty); if (!string.IsNullOrEmpty(uniqueId)) { @@ -2410,7 +2414,7 @@ namespace Emby.Server.Implementations.Library var refresh = isNew || DateTime.UtcNow - item.DateLastRefreshed >= _viewRefreshInterval; - if (!refresh && !item.DisplayParentId.Equals(Guid.Empty)) + if (!refresh && !item.DisplayParentId.Equals(default)) { var displayParent = GetItemById(item.DisplayParentId); refresh = displayParent != null && displayParent.DateLastSaved > item.DateLastRefreshed; diff --git a/Emby.Server.Implementations/Library/MediaSourceManager.cs b/Emby.Server.Implementations/Library/MediaSourceManager.cs index eb95977ef..c9202c264 100644 --- a/Emby.Server.Implementations/Library/MediaSourceManager.cs +++ b/Emby.Server.Implementations/Library/MediaSourceManager.cs @@ -514,10 +514,10 @@ namespace Emby.Server.Implementations.Library _logger.LogInformation("Live stream opened: {@MediaSource}", mediaSource); var clone = JsonSerializer.Deserialize<MediaSourceInfo>(json, _jsonOptions); - if (!request.UserId.Equals(Guid.Empty)) + if (!request.UserId.Equals(default)) { var user = _userManager.GetUserById(request.UserId); - var item = request.ItemId.Equals(Guid.Empty) + var item = request.ItemId.Equals(default) ? null : _libraryManager.GetItemById(request.ItemId); SetDefaultAudioAndSubtitleStreamIndexes(item, clone, user); diff --git a/Emby.Server.Implementations/Library/MusicManager.cs b/Emby.Server.Implementations/Library/MusicManager.cs index d35e74e7b..b2439a87e 100644 --- a/Emby.Server.Implementations/Library/MusicManager.cs +++ b/Emby.Server.Implementations/Library/MusicManager.cs @@ -80,7 +80,7 @@ namespace Emby.Server.Implementations.Library { return Guid.Empty; } - }).Where(i => !i.Equals(Guid.Empty)).ToArray(); + }).Where(i => !i.Equals(default)).ToArray(); return GetInstantMixFromGenreIds(genreIds, user, dtoOptions); } diff --git a/Emby.Server.Implementations/Library/SearchEngine.cs b/Emby.Server.Implementations/Library/SearchEngine.cs index 70d9cbc98..96702d152 100644 --- a/Emby.Server.Implementations/Library/SearchEngine.cs +++ b/Emby.Server.Implementations/Library/SearchEngine.cs @@ -30,7 +30,7 @@ namespace Emby.Server.Implementations.Library public QueryResult<SearchHintInfo> GetSearchHints(SearchQuery query) { User user = null; - if (query.UserId != Guid.Empty) + if (!query.UserId.Equals(default)) { user = _userManager.GetUserById(query.UserId); } @@ -168,10 +168,10 @@ namespace Emby.Server.Implementations.Library { Fields = new ItemFields[] { - ItemFields.AirTime, - ItemFields.DateCreated, - ItemFields.ChannelInfo, - ItemFields.ParentId + ItemFields.AirTime, + ItemFields.DateCreated, + ItemFields.ChannelInfo, + ItemFields.ParentId } } }; @@ -180,12 +180,12 @@ namespace Emby.Server.Implementations.Library if (searchQuery.IncludeItemTypes.Length == 1 && searchQuery.IncludeItemTypes[0] == BaseItemKind.MusicArtist) { - if (!searchQuery.ParentId.Equals(Guid.Empty)) + if (!searchQuery.ParentId.Equals(default)) { searchQuery.AncestorIds = new[] { searchQuery.ParentId }; + searchQuery.ParentId = Guid.Empty; } - searchQuery.ParentId = Guid.Empty; searchQuery.IncludeItemsByName = true; searchQuery.IncludeItemTypes = Array.Empty<BaseItemKind>(); mediaItems = _libraryManager.GetAllArtists(searchQuery).Items.Select(i => i.Item).ToList(); diff --git a/Emby.Server.Implementations/Library/UserViewManager.cs b/Emby.Server.Implementations/Library/UserViewManager.cs index b00bc72e6..ec411aa3b 100644 --- a/Emby.Server.Implementations/Library/UserViewManager.cs +++ b/Emby.Server.Implementations/Library/UserViewManager.cs @@ -142,7 +142,7 @@ namespace Emby.Server.Implementations.Library if (index == -1 && i is UserView view - && view.DisplayParentId != Guid.Empty) + && !view.DisplayParentId.Equals(default)) { index = Array.IndexOf(orders, view.DisplayParentId); } @@ -214,7 +214,7 @@ namespace Emby.Server.Implementations.Library } else { - var current = list.FirstOrDefault(i => i.Item1 != null && i.Item1.Id == container.Id); + var current = list.FirstOrDefault(i => i.Item1 != null && i.Item1.Id.Equals(container.Id)); if (current != null) { @@ -244,7 +244,7 @@ namespace Emby.Server.Implementations.Library var parents = new List<BaseItem>(); - if (!parentId.Equals(Guid.Empty)) + if (!parentId.Equals(default)) { var parentItem = _libraryManager.GetItemById(parentId); if (parentItem is Channel) |
