From 22d8528d904e69a8e22ba0e6d43dcb58a54bdcf5 Mon Sep 17 00:00:00 2001 From: gnattu Date: Mon, 5 Aug 2024 10:58:22 -0400 Subject: Backport pull request #11901 from jellyfin/release-10.9.z Implement Device Cache to replace EFCoreSecondLevelCacheInterceptor Original-merge: b7bc0e1c96553675a490c0bd92a58ad9c5f0d0e1 Merged-by: joshuaboniface Backported-by: Bond_009 --- .../Security/AuthorizationContext.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'Jellyfin.Server.Implementations/Security') diff --git a/Jellyfin.Server.Implementations/Security/AuthorizationContext.cs b/Jellyfin.Server.Implementations/Security/AuthorizationContext.cs index 6bda12c5b4..2ae722982a 100644 --- a/Jellyfin.Server.Implementations/Security/AuthorizationContext.cs +++ b/Jellyfin.Server.Implementations/Security/AuthorizationContext.cs @@ -4,7 +4,10 @@ using System; using System.Collections.Generic; using System.Net; using System.Threading.Tasks; +using Jellyfin.Data.Queries; +using Jellyfin.Extensions; using MediaBrowser.Controller; +using MediaBrowser.Controller.Devices; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Net; using Microsoft.AspNetCore.Http; @@ -17,15 +20,18 @@ namespace Jellyfin.Server.Implementations.Security { private readonly IDbContextFactory _jellyfinDbProvider; private readonly IUserManager _userManager; + private readonly IDeviceManager _deviceManager; private readonly IServerApplicationHost _serverApplicationHost; public AuthorizationContext( IDbContextFactory jellyfinDb, IUserManager userManager, + IDeviceManager deviceManager, IServerApplicationHost serverApplicationHost) { _jellyfinDbProvider = jellyfinDb; _userManager = userManager; + _deviceManager = deviceManager; _serverApplicationHost = serverApplicationHost; } @@ -121,7 +127,11 @@ namespace Jellyfin.Server.Implementations.Security var dbContext = await _jellyfinDbProvider.CreateDbContextAsync().ConfigureAwait(false); await using (dbContext.ConfigureAwait(false)) { - var device = await dbContext.Devices.FirstOrDefaultAsync(d => d.AccessToken == token).ConfigureAwait(false); + var device = _deviceManager.GetDevices( + new DeviceQuery + { + AccessToken = token + }).Items.FirstOrDefault(); if (device is not null) { @@ -178,8 +188,7 @@ namespace Jellyfin.Server.Implementations.Security if (updateToken) { - dbContext.Devices.Update(device); - await dbContext.SaveChangesAsync().ConfigureAwait(false); + await _deviceManager.UpdateDevice(device).ConfigureAwait(false); } } else -- cgit v1.2.3