diff --git a/Jellyfin.Data/Entities/User.cs b/Jellyfin.Data/Entities/User.cs
index f09b36bde0..cd6cad9921 100644
--- a/Jellyfin.Data/Entities/User.cs
+++ b/Jellyfin.Data/Entities/User.cs
@@ -420,10 +420,7 @@ namespace Jellyfin.Data.Entities
/// A string array containing the user's preferences.
public string[] GetPreference(PreferenceKind preference)
{
- var val = Preferences
- .Where(p => p.Kind == preference)
- .Select(p => p.Value)
- .First();
+ var val = Preferences.First(p => p.Kind == preference).Value;
return Equals(val, string.Empty) ? Array.Empty() : val.Split(Delimiter);
}
diff --git a/Jellyfin.Server.Implementations/Users/UserManager.cs b/Jellyfin.Server.Implementations/Users/UserManager.cs
index 91d0e5b803..01151e65e4 100644
--- a/Jellyfin.Server.Implementations/Users/UserManager.cs
+++ b/Jellyfin.Server.Implementations/Users/UserManager.cs
@@ -84,24 +84,10 @@ namespace Jellyfin.Server.Implementations.Users
public event EventHandler> OnUserLockedOut;
///
- public IEnumerable Users
- {
- get
- {
- var dbContext = _dbProvider.CreateContext();
- return dbContext.Users;
- }
- }
+ public IEnumerable Users => _dbProvider.CreateContext().Users;
///
- public IEnumerable UsersIds
- {
- get
- {
- var dbContext = _dbProvider.CreateContext();
- return dbContext.Users.Select(u => u.Id);
- }
- }
+ public IEnumerable UsersIds => _dbProvider.CreateContext().Users.Select(u => u.Id);
///
public User GetUserById(Guid id)
@@ -111,9 +97,7 @@ namespace Jellyfin.Server.Implementations.Users
throw new ArgumentException("Guid can't be empty", nameof(id));
}
- var dbContext = _dbProvider.CreateContext();
-
- return dbContext.Users.Find(id);
+ return _dbProvider.CreateContext().Users.Find(id);
}
///
@@ -124,11 +108,9 @@ namespace Jellyfin.Server.Implementations.Users
throw new ArgumentException("Invalid username", nameof(name));
}
- var dbContext = _dbProvider.CreateContext();
-
// This can't use an overload with StringComparer because that would cause the query to
// have to be evaluated client-side.
- return dbContext.Users.FirstOrDefault(u => string.Equals(u.Username, name));
+ return _dbProvider.CreateContext().Users.FirstOrDefault(u => string.Equals(u.Username, name));
}
///
diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs
index 2f9bc38df3..4af74f9cd2 100644
--- a/MediaBrowser.Controller/Entities/Folder.cs
+++ b/MediaBrowser.Controller/Entities/Folder.cs
@@ -182,12 +182,13 @@ namespace MediaBrowser.Controller.Entities
{
if (this is ICollectionFolder && !(this is BasePluginFolder))
{
- if (user.GetPreference(PreferenceKind.BlockedMediaFolders) != null)
+ var blockedMediaFolders = user.GetPreference(PreferenceKind.BlockedMediaFolders);
+ if (blockedMediaFolders.Length > 0)
{
- if (user.GetPreference(PreferenceKind.BlockedMediaFolders).Contains(Id.ToString("N", CultureInfo.InvariantCulture), StringComparer.OrdinalIgnoreCase) ||
+ if (blockedMediaFolders.Contains(Id.ToString("N", CultureInfo.InvariantCulture), StringComparer.OrdinalIgnoreCase) ||
// Backwards compatibility
- user.GetPreference(PreferenceKind.BlockedMediaFolders).Contains(Name, StringComparer.OrdinalIgnoreCase))
+ blockedMediaFolders.Contains(Name, StringComparer.OrdinalIgnoreCase))
{
return false;
}