diff --git a/common/ASC.Core.Common/Data/DbUserService.cs b/common/ASC.Core.Common/Data/DbUserService.cs index 805a462ec7..d9fb28dd4d 100644 --- a/common/ASC.Core.Common/Data/DbUserService.cs +++ b/common/ASC.Core.Common/Data/DbUserService.cs @@ -26,6 +26,8 @@ using ASC.Core.Common.EF; +using Microsoft.EntityFrameworkCore; + namespace ASC.Core.Data; [Scope] @@ -550,53 +552,45 @@ public class EFUserService : IUserService public void SetUserPhoto(int tenant, Guid id, byte[] photo) { using var userDbContext = _dbContextFactory.CreateDbContext(); - var strategy = userDbContext.Database.CreateExecutionStrategy(); - strategy.Execute(async () => + var userPhoto = userDbContext.Photos.FirstOrDefault(r => r.UserId == id && r.Tenant == tenant); + + if (photo != null && photo.Length != 0) { - using var userDbContext = _dbContextFactory.CreateDbContext(); - using var tr = await userDbContext.Database.BeginTransactionAsync(); - - var userPhoto = await userDbContext.Photos.FirstOrDefaultAsync(r => r.UserId == id && r.Tenant == tenant); - - if (photo != null && photo.Length != 0) + if (userPhoto == null) { - if (userPhoto == null) + userPhoto = new UserPhoto { - userPhoto = new UserPhoto - { - Tenant = tenant, - UserId = id, - Photo = photo - }; - } - else - { - userPhoto.Photo = photo; - } - - - await userDbContext.AddOrUpdateAsync(r => userDbContext.Photos, userPhoto); - - var userEntity = new User - { - Id = id, - LastModified = DateTime.UtcNow, - Tenant = tenant + Tenant = tenant, + UserId = id, + Photo = photo }; - - userDbContext.Entry(userEntity).Property(x => x.LastModified).IsModified = true; - } - else if (userPhoto != null) + else { - userDbContext.Photos.Remove(userPhoto); + userPhoto.Photo = photo; } - await userDbContext.SaveChangesAsync(); - await tr.CommitAsync(); - }).GetAwaiter() - .GetResult(); + + userDbContext.AddOrUpdate(userDbContext.Photos, userPhoto); + + var userEntity = new User + { + Id = id, + LastModified = DateTime.UtcNow, + Tenant = tenant + }; + + userDbContext.Users.Attach(userEntity); + userDbContext.Entry(userEntity).Property(x => x.LastModified).IsModified = true; + + } + else if (userPhoto != null) + { + userDbContext.Photos.Remove(userPhoto); + } + + userDbContext.SaveChanges(); } private IQueryable GetUserQuery(UserDbContext userDbContext, int tenant) diff --git a/products/ASC.People/Server/Api/PhotoController.cs b/products/ASC.People/Server/Api/PhotoController.cs index 69239e0ff5..0a5443f1e8 100644 --- a/products/ASC.People/Server/Api/PhotoController.cs +++ b/products/ASC.People/Server/Api/PhotoController.cs @@ -207,14 +207,14 @@ public class PhotoController : PeopleControllerBase throw new ImageSizeLimitException(); } - var mainPhoto = _userPhotoManager.SaveOrUpdatePhoto(userId, data); + var mainPhoto = await _userPhotoManager.SaveOrUpdatePhoto(userId, data); var userInfo = _userManager.GetUsers(userId); var cacheKey = Math.Abs(userInfo.LastModified.GetHashCode()); result.Data = new { - main = (await mainPhoto).Item1 + $"?hash={cacheKey}", + main = mainPhoto.Item1 + $"?hash={cacheKey}", retina = await _userPhotoManager.GetRetinaPhotoURL(userId) + $"?hash={cacheKey}", max = await _userPhotoManager.GetMaxPhotoURL(userId) + $"?hash={cacheKey}", big = await _userPhotoManager.GetBigPhotoURL(userId) + $"?hash={cacheKey}", diff --git a/web/ASC.Web.Core/Users/UserPhotoManager.cs b/web/ASC.Web.Core/Users/UserPhotoManager.cs index c785466796..8b8e8273bb 100644 --- a/web/ASC.Web.Core/Users/UserPhotoManager.cs +++ b/web/ASC.Web.Core/Users/UserPhotoManager.cs @@ -546,7 +546,7 @@ public class UserPhotoManager data = TryParseImage(data, -1, OriginalFotoSize, out _, out var width, out var height); _userManager.SaveUserPhoto(userID, data); SetUserPhotoThumbnailSettings(userID, width, height); - _userPhotoManagerCache.ClearCache(userID, _tenantManager.GetCurrentTenant().Id); + // _userPhotoManagerCache.ClearCache(userID, _tenantManager.GetCurrentTenant().Id); } @@ -561,8 +561,7 @@ public class UserPhotoManager { _userManager.SaveUserPhoto(userID, data); SetUserPhotoThumbnailSettings(userID, width, height); - _userPhotoManagerCache.ClearCache(userID, _tenantManager.GetCurrentTenant().Id); - + // _userPhotoManagerCache.ClearCache(userID, _tenantManager.GetCurrentTenant().Id); } var store = GetDataStore();