Restructure query to avoid extra database access.
This commit is contained in:
parent
8a9ec7809f
commit
5f67ba4d70
|
@ -1,4 +1,6 @@
|
||||||
using System;
|
#pragma warning disable CA1307
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Jellyfin.Data.Entities;
|
using Jellyfin.Data.Entities;
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
|
@ -26,14 +28,15 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
public DisplayPreferences GetDisplayPreferences(Guid userId, string client)
|
public DisplayPreferences GetDisplayPreferences(Guid userId, string client)
|
||||||
{
|
{
|
||||||
using var dbContext = _dbProvider.CreateContext();
|
using var dbContext = _dbProvider.CreateContext();
|
||||||
var user = dbContext.Users.Find(userId);
|
var prefs = dbContext.DisplayPreferences
|
||||||
#pragma warning disable CA1307
|
.Include(pref => pref.HomeSections)
|
||||||
var prefs = user.DisplayPreferences.FirstOrDefault(pref => string.Equals(pref.Client, client));
|
.FirstOrDefault(pref =>
|
||||||
|
pref.UserId == userId && pref.ItemId == null && string.Equals(pref.Client, client));
|
||||||
|
|
||||||
if (prefs == null)
|
if (prefs == null)
|
||||||
{
|
{
|
||||||
prefs = new DisplayPreferences(client, userId);
|
prefs = new DisplayPreferences(client, userId);
|
||||||
user.DisplayPreferences.Add(prefs);
|
dbContext.DisplayPreferences.Add(prefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return prefs;
|
return prefs;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user