diff --git a/Jellyfin.Server.Implementations/Devices/DeviceManager.cs b/Jellyfin.Server.Implementations/Devices/DeviceManager.cs index cb173e5fdf..28794ada2d 100644 --- a/Jellyfin.Server.Implementations/Devices/DeviceManager.cs +++ b/Jellyfin.Server.Implementations/Devices/DeviceManager.cs @@ -27,8 +27,8 @@ namespace Jellyfin.Server.Implementations.Devices private readonly IDbContextFactory _dbProvider; private readonly IUserManager _userManager; private readonly ConcurrentDictionary _capabilitiesMap = new(); - private readonly IDictionary _devices; - private readonly IDictionary _deviceOptions; + private readonly ConcurrentDictionary _devices; + private readonly ConcurrentDictionary _deviceOptions; /// /// Initializes a new instance of the class. @@ -48,14 +48,14 @@ namespace Jellyfin.Server.Implementations.Devices .OrderBy(d => d.Id) .AsEnumerable()) { - _devices.Add(device.Id, device); + _devices.TryAdd(device.Id, device); } foreach (var deviceOption in dbContext.DeviceOptions .OrderBy(d => d.Id) .AsEnumerable()) { - _deviceOptions.Add(deviceOption.DeviceId, deviceOption); + _deviceOptions.TryAdd(deviceOption.DeviceId, deviceOption); } } @@ -104,7 +104,7 @@ namespace Jellyfin.Server.Implementations.Devices .Include(d => d.User) .FirstOrDefaultAsync(d => d.Id == device.Id) .ConfigureAwait(false); - _devices.Add(device.Id, newDevice!); + _devices.TryAdd(device.Id, newDevice!); } return device; @@ -205,7 +205,7 @@ namespace Jellyfin.Server.Implementations.Devices public async Task DeleteDevice(Device device) { var id = _devices.FirstOrDefault(x => x.Value.Equals(device)).Key; - _devices.Remove(id); + _devices.TryRemove(id, out _); var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false); await using (dbContext.ConfigureAwait(false)) {