From f50a250cd9fac47bcbd9a05e99c8ffe4d294e320 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Mon, 21 Feb 2022 14:15:09 +0100 Subject: Optimize Guid comparisons * Use Guid.Equals(Guid) instead of the == override * Ban the usage of Guid.Equals(Object) to prevent accidental boxing * Compare to default(Guid) instead of Guid.Empty --- Jellyfin.Server.Implementations/Users/UserManager.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'Jellyfin.Server.Implementations/Users/UserManager.cs') diff --git a/Jellyfin.Server.Implementations/Users/UserManager.cs b/Jellyfin.Server.Implementations/Users/UserManager.cs index c41b343c7..2100fa6d5 100644 --- a/Jellyfin.Server.Implementations/Users/UserManager.cs +++ b/Jellyfin.Server.Implementations/Users/UserManager.cs @@ -107,7 +107,7 @@ namespace Jellyfin.Server.Implementations.Users /// public User? GetUserById(Guid id) { - if (id == Guid.Empty) + if (id.Equals(default)) { throw new ArgumentException("Guid can't be empty", nameof(id)); } @@ -146,8 +146,7 @@ namespace Jellyfin.Server.Implementations.Users if (await dbContext.Users .AsQueryable() - .Where(u => u.Username == newName && u.Id != user.Id) - .AnyAsync() + .AnyAsync(u => u.Username == newName && !u.Id.Equals(user.Id)) .ConfigureAwait(false)) { throw new ArgumentException(string.Format( @@ -597,7 +596,7 @@ namespace Jellyfin.Server.Implementations.Users .Include(u => u.Preferences) .Include(u => u.AccessSchedules) .Include(u => u.ProfileImage) - .FirstOrDefault(u => u.Id == userId) + .FirstOrDefault(u => u.Id.Equals(userId)) ?? throw new ArgumentException("No user exists with given Id!"); user.SubtitleMode = config.SubtitleMode; @@ -631,7 +630,7 @@ namespace Jellyfin.Server.Implementations.Users .Include(u => u.Preferences) .Include(u => u.AccessSchedules) .Include(u => u.ProfileImage) - .FirstOrDefault(u => u.Id == userId) + .FirstOrDefault(u => u.Id.Equals(userId)) ?? throw new ArgumentException("No user exists with given Id!"); // The default number of login attempts is 3, but for some god forsaken reason it's sent to the server as "0" -- cgit v1.2.3