diff options
| author | Patrick Barron <barronpm@gmail.com> | 2020-07-22 15:21:50 -0400 |
|---|---|---|
| committer | Patrick Barron <barronpm@gmail.com> | 2020-07-22 15:21:50 -0400 |
| commit | 5f67ba4d7087d7a0cad37fc9e2db212340076d12 (patch) | |
| tree | 32d748f4fad792315322adbc0fc40ee78a1926db | |
| parent | 8a9ec7809fab05a30ff8e5f13b38b9d34ed15050 (diff) | |
Restructure query to avoid extra database access.
| -rw-r--r-- | Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs b/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs index 4ad9a12d4..b7c65fc2c 100644 --- a/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs +++ b/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs @@ -1,4 +1,6 @@ -using System; +#pragma warning disable CA1307 + +using System; using System.Linq; using Jellyfin.Data.Entities; using MediaBrowser.Controller; @@ -26,14 +28,15 @@ namespace Jellyfin.Server.Implementations.Users public DisplayPreferences GetDisplayPreferences(Guid userId, string client) { using var dbContext = _dbProvider.CreateContext(); - var user = dbContext.Users.Find(userId); -#pragma warning disable CA1307 - var prefs = user.DisplayPreferences.FirstOrDefault(pref => string.Equals(pref.Client, client)); + var prefs = dbContext.DisplayPreferences + .Include(pref => pref.HomeSections) + .FirstOrDefault(pref => + pref.UserId == userId && pref.ItemId == null && string.Equals(pref.Client, client)); if (prefs == null) { prefs = new DisplayPreferences(client, userId); - user.DisplayPreferences.Add(prefs); + dbContext.DisplayPreferences.Add(prefs); } return prefs; |
