people: fixed generate thumbnails

This commit is contained in:
Alexey Bannov 2023-04-13 14:44:22 +03:00
parent 6a059746ba
commit 2b17d2eed0
3 changed files with 36 additions and 43 deletions

View File

@ -26,6 +26,8 @@
using ASC.Core.Common.EF;
using Microsoft.EntityFrameworkCore;
namespace ASC.Core.Data;
[Scope]
@ -550,14 +552,8 @@ 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 () =>
{
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);
var userPhoto = userDbContext.Photos.FirstOrDefault(r => r.UserId == id && r.Tenant == tenant);
if (photo != null && photo.Length != 0)
{
@ -576,7 +572,7 @@ public class EFUserService : IUserService
}
await userDbContext.AddOrUpdateAsync(r => userDbContext.Photos, userPhoto);
userDbContext.AddOrUpdate(userDbContext.Photos, userPhoto);
var userEntity = new User
{
@ -585,6 +581,7 @@ public class EFUserService : IUserService
Tenant = tenant
};
userDbContext.Users.Attach(userEntity);
userDbContext.Entry(userEntity).Property(x => x.LastModified).IsModified = true;
}
@ -593,10 +590,7 @@ public class EFUserService : IUserService
userDbContext.Photos.Remove(userPhoto);
}
await userDbContext.SaveChangesAsync();
await tr.CommitAsync();
}).GetAwaiter()
.GetResult();
userDbContext.SaveChanges();
}
private IQueryable<User> GetUserQuery(UserDbContext userDbContext, int tenant)

View File

@ -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}",

View File

@ -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();