diff options
| author | Bond_009 <bond.009@outlook.com> | 2022-02-21 14:15:09 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2022-02-21 14:15:09 +0100 |
| commit | f50a250cd9fac47bcbd9a05e99c8ffe4d294e320 (patch) | |
| tree | b205dccb83ad385b0ac338b00680aa4f97fe9b97 /Jellyfin.Server.Implementations/Users/UserManager.cs | |
| parent | bbac59c6d627ef3ef67e26b10d6571cd9a260466 (diff) | |
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
Diffstat (limited to 'Jellyfin.Server.Implementations/Users/UserManager.cs')
| -rw-r--r-- | Jellyfin.Server.Implementations/Users/UserManager.cs | 9 |
1 files changed, 4 insertions, 5 deletions
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 /// <inheritdoc/> 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" |
