瀏覽代碼

Don't cache user in DeviceManager, query from user cache instead

Signed-off-by: gnattu <gnattuoc@me.com>
gnattu 11 月之前
父節點
當前提交
79c0a7d7f0
共有 1 個文件被更改,包括 6 次插入3 次删除
  1. 6 3
      Jellyfin.Server.Implementations/Devices/DeviceManager.cs

+ 6 - 3
Jellyfin.Server.Implementations/Devices/DeviceManager.cs

@@ -44,7 +44,6 @@ namespace Jellyfin.Server.Implementations.Devices
 
 
             using var dbContext = _dbProvider.CreateDbContext();
             using var dbContext = _dbProvider.CreateDbContext();
             foreach (var device in dbContext.Devices
             foreach (var device in dbContext.Devices
-                         .Include(d => d.User)
                          .OrderBy(d => d.Id)
                          .OrderBy(d => d.Id)
                          .AsEnumerable())
                          .AsEnumerable())
             {
             {
@@ -101,7 +100,6 @@ namespace Jellyfin.Server.Implementations.Devices
 
 
                 await dbContext.SaveChangesAsync().ConfigureAwait(false);
                 await dbContext.SaveChangesAsync().ConfigureAwait(false);
                 var newDevice = await dbContext.Devices
                 var newDevice = await dbContext.Devices
-                    .Include(d => d.User)
                     .FirstOrDefaultAsync(d => d.Id == device.Id)
                     .FirstOrDefaultAsync(d => d.Id == device.Id)
                     .ConfigureAwait(false);
                     .ConfigureAwait(false);
                 _devices.TryAdd(device.Id, newDevice!);
                 _devices.TryAdd(device.Id, newDevice!);
@@ -239,6 +237,11 @@ namespace Jellyfin.Server.Implementations.Devices
         private DeviceInfo ToDeviceInfo(Device authInfo, DeviceOptions? options = null)
         private DeviceInfo ToDeviceInfo(Device authInfo, DeviceOptions? options = null)
         {
         {
             var caps = GetCapabilities(authInfo.DeviceId);
             var caps = GetCapabilities(authInfo.DeviceId);
+            var user = _userManager.GetUserById(authInfo.UserId);
+            if (user is null)
+            {
+                throw new ResourceNotFoundException();
+            }
 
 
             return new DeviceInfo
             return new DeviceInfo
             {
             {
@@ -246,7 +249,7 @@ namespace Jellyfin.Server.Implementations.Devices
                 AppVersion = authInfo.AppVersion,
                 AppVersion = authInfo.AppVersion,
                 Id = authInfo.DeviceId,
                 Id = authInfo.DeviceId,
                 LastUserId = authInfo.UserId,
                 LastUserId = authInfo.UserId,
-                LastUserName = authInfo.User.Username,
+                LastUserName = user.Username,
                 Name = authInfo.DeviceName,
                 Name = authInfo.DeviceName,
                 DateLastActivity = authInfo.DateLastActivity,
                 DateLastActivity = authInfo.DateLastActivity,
                 IconUrl = caps.IconUrl,
                 IconUrl = caps.IconUrl,