The Free Software Media System - Server Backend & API
Convert some code in UserManager to async
Patrick Barron72263613d039
diff --git a/Jellyfin.Api/Controllers/ImageController.cs b/Jellyfin.Api/Controllers/ImageController.csindex 05efe23553..4a67c1aede 100644--- a/Jellyfin.Api/Controllers/ImageController.cs+++ b/Jellyfin.Api/Controllers/ImageController.cs@@ -109,7 +109,7 @@ namespace Jellyfin.Api.Controllersvar userDataPath = Path.Combine(_serverConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath, user.Username);if (user.ProfileImage != null){- _userManager.ClearProfileImage(user);+ await _userManager.ClearProfileImageAsync(user).ConfigureAwait(false);}user.ProfileImage = new Data.Entities.ImageInfo(Path.Combine(userDataPath, "profile" + MimeTypes.ToExtension(mimeType)));@@ -138,7 +138,7 @@ namespace Jellyfin.Api.Controllers[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "index", Justification = "Imported from ServiceStack")][ProducesResponseType(StatusCodes.Status204NoContent)][ProducesResponseType(StatusCodes.Status403Forbidden)]- public ActionResult DeleteUserImage(+ public async Task<ActionResult> DeleteUserImage([FromRoute, Required] Guid userId,[FromRoute, Required] ImageType imageType,[FromRoute] int? index = null)@@ -158,7 +158,7 @@ namespace Jellyfin.Api.Controllers_logger.LogError(e, "Error deleting user profile image:");}- _userManager.ClearProfileImage(user);+ await _userManager.ClearProfileImageAsync(user).ConfigureAwait(false);return NoContent();}diff --git a/Jellyfin.Api/Controllers/UserController.cs b/Jellyfin.Api/Controllers/UserController.csindex 50bb8bb2aa..7b0897bfb9 100644--- a/Jellyfin.Api/Controllers/UserController.cs+++ b/Jellyfin.Api/Controllers/UserController.cs@@ -381,17 +381,13 @@ namespace Jellyfin.Api.Controllersvar user = _userManager.GetUserById(userId);- if (string.Equals(user.Username, updateUser.Name, StringComparison.Ordinal))- {- await _userManager.UpdateUserAsync(user).ConfigureAwait(false);- _userManager.UpdateConfiguration(user.Id, updateUser.Configuration);- }- else+ if (!string.Equals(user.Username, updateUser.Name, StringComparison.Ordinal)){await _userManager.RenameUser(user, updateUser.Name).ConfigureAwait(false);- _userManager.UpdateConfiguration(updateUser.Id, updateUser.Configuration);}+ await _userManager.UpdateConfigurationAsync(user.Id, updateUser.Configuration).ConfigureAwait(false);+return NoContent();}@@ -409,7 +405,7 @@ namespace Jellyfin.Api.Controllers[ProducesResponseType(StatusCodes.Status204NoContent)][ProducesResponseType(StatusCodes.Status400BadRequest)][ProducesResponseType(StatusCodes.Status403Forbidden)]- public ActionResult UpdateUserPolicy(+ public async Task<ActionResult> UpdateUserPolicy([FromRoute, Required] Guid userId,[FromBody] UserPolicy newPolicy){@@ -447,7 +443,7 @@ namespace Jellyfin.Api.Controllers_sessionManager.RevokeUserTokens(user.Id, currentToken);}- _userManager.UpdatePolicy(userId, newPolicy);+ await _userManager.UpdatePolicyAsync(userId, newPolicy).ConfigureAwait(false);return NoContent();}@@ -464,7 +460,7 @@ namespace Jellyfin.Api.Controllers[Authorize(Policy = Policies.DefaultAuthorization)][ProducesResponseType(StatusCodes.Status204NoContent)][ProducesResponseType(StatusCodes.Status403Forbidden)]- public ActionResult UpdateUserConfiguration(+ public async Task<ActionResult> UpdateUserConfiguration([FromRoute, Required] Guid userId,[FromBody] UserConfiguration userConfig){@@ -473,7 +469,7 @@ namespace Jellyfin.Api.Controllersreturn Forbid("User configuration update not allowed");}- _userManager.UpdateConfiguration(userId, userConfig);+ await _userManager.UpdateConfigurationAsync(userId, userConfig).ConfigureAwait(false);return NoContent();}diff --git a/Jellyfin.Server.Implementations/Users/UserManager.cs b/Jellyfin.Server.Implementations/Users/UserManager.csindex b41a5ee5ca..40b89ed284 100644--- a/Jellyfin.Server.Implementations/Users/UserManager.cs+++ b/Jellyfin.Server.Implementations/Users/UserManager.cs@@ -434,9 +434,7 @@ namespace Jellyfin.Server.Implementations.Usersif (authenticationProvider is IHasNewUserPolicy hasNewUserPolicy && user != null){- UpdatePolicy(user.Id, hasNewUserPolicy.GetNewUserPolicy());-- await UpdateUserAsync(user).ConfigureAwait(false);+ await UpdatePolicyAsync(user.Id, hasNewUserPolicy.GetNewUserPolicy()).ConfigureAwait(false);}}}@@ -615,9 +613,9 @@ namespace Jellyfin.Server.Implementations.Users}/// <inheritdoc/>- public void UpdateConfiguration(Guid userId, UserConfiguration config)+ public async Task UpdateConfigurationAsync(Guid userId, UserConfiguration config){- using var dbContext = _dbProvider.CreateContext();+ await using var dbContext = _dbProvider.CreateContext();var user = dbContext.Users.Include(u => u.Permissions).Include(u => u.Preferences)@@ -644,13 +642,13 @@ namespace Jellyfin.Server.Implementations.Usersuser.SetPreference(PreferenceKind.LatestItemExcludes, config.LatestItemsExcludes);dbContext.Update(user);- dbContext.SaveChanges();+ await dbContext.SaveChangesAsync().ConfigureAwait(false);}/// <inheritdoc/>- public void UpdatePolicy(Guid userId, UserPolicy policy)+ public async Task UpdatePolicyAsync(Guid userId, UserPolicy policy){- using var dbContext = _dbProvider.CreateContext();+ await using var dbContext = _dbProvider.CreateContext();var user = dbContext.Users.Include(u => u.Permissions).Include(u => u.Preferences)@@ -715,15 +713,15 @@ namespace Jellyfin.Server.Implementations.Usersuser.SetPreference(PreferenceKind.EnableContentDeletionFromFolders, policy.EnableContentDeletionFromFolders);dbContext.Update(user);- dbContext.SaveChanges();+ await dbContext.SaveChangesAsync().ConfigureAwait(false);}/// <inheritdoc/>- public void ClearProfileImage(User user)+ public async Task ClearProfileImageAsync(User user){- using var dbContext = _dbProvider.CreateContext();+ await using var dbContext = _dbProvider.CreateContext();dbContext.Remove(user.ProfileImage);- dbContext.SaveChanges();+ await dbContext.SaveChangesAsync().ConfigureAwait(false);user.ProfileImage = null;}diff --git a/MediaBrowser.Controller/Library/IUserManager.cs b/MediaBrowser.Controller/Library/IUserManager.csindex 6a4f5cf679..8fd3b8c347 100644--- a/MediaBrowser.Controller/Library/IUserManager.cs+++ b/MediaBrowser.Controller/Library/IUserManager.cs@@ -158,7 +158,8 @@ namespace MediaBrowser.Controller.Library/// </summary>/// <param name="userId">The user's Id.</param>/// <param name="config">The request containing the new user configuration.</param>- void UpdateConfiguration(Guid userId, UserConfiguration config);+ /// <returns>A task representing the update.</returns>+ Task UpdateConfigurationAsync(Guid userId, UserConfiguration config);/// <summary>/// This method updates the user's policy.@@ -167,12 +168,14 @@ namespace MediaBrowser.Controller.Library/// </summary>/// <param name="userId">The user's Id.</param>/// <param name="policy">The request containing the new user policy.</param>- void UpdatePolicy(Guid userId, UserPolicy policy);+ /// <returns>A task representing the update.</returns>+ Task UpdatePolicyAsync(Guid userId, UserPolicy policy);/// <summary>/// Clears the user's profile image./// </summary>/// <param name="user">The user.</param>- void ClearProfileImage(User user);+ /// <returns>A task representing the clearing of the profile image.</returns>+ Task ClearProfileImageAsync(User user);}}