Quota: fix

This commit is contained in:
Nikolay Rechkin 2022-10-24 17:26:29 +03:00
parent 60f2393940
commit b33d55cfe7
3 changed files with 12 additions and 11 deletions

View File

@ -130,9 +130,10 @@ public class FilesSpaceUsageStatManager : SpaceUsageStatManager, IUserSpaceUsage
.SumAsync(r => r.ContentLength);
}
public void RecalculateUserQuota(int TenantId, Guid userId)
public async Task RecalculateUserQuota(int TenantId, Guid userId)
{
var size = GetUserSpaceUsageAsync(userId).Result;
_tenantManager.SetCurrentTenant(TenantId);
var size = await GetUserSpaceUsageAsync(userId);
_tenantManager.SetTenantQuotaRow(
new TenantQuotaRow { Tenant = TenantId, Path = $"/{FileConstant.ModuleId}/", Counter = size, Tag = WebItemManager.DocumentsProductID.ToString(), UserId = userId, LastModified = DateTime.UtcNow },

View File

@ -49,14 +49,14 @@ public class UsersQuotaSyncOperation
{
item = _serviceProvider.GetRequiredService<UsersQuotaSyncJob>();
item.InitJob(tenant);
_progressQueue.EnqueueTask(item);
_progressQueue.EnqueueTask(item.RunJobAsync, item);
}
item.PublishChanges();
}
public UsersQuotaSyncOperation(IServiceProvider serviceProvider, IDistributedTaskQueueFactory queueFactory)
public UsersQuotaSyncOperation(IServiceProvider serviceProvider, IDistributedTaskQueueFactory queueFactory, IServiceScopeFactory serviceScopeFactory)
{
;
_serviceProvider = serviceProvider;
@ -78,7 +78,6 @@ public class UsersQuotaSyncOperation
public class UsersQuotaSyncJob : DistributedTaskProgress
{
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly IDaoFactory _daoFactory;
protected readonly IDbContextFactory<FilesDbContext> _dbContextFactory;
@ -97,16 +96,15 @@ public class UsersQuotaSyncJob : DistributedTaskProgress
}
}
public UsersQuotaSyncJob(IServiceScopeFactory serviceScopeFactory, IDaoFactory daoFactory)
public UsersQuotaSyncJob(IServiceScopeFactory serviceScopeFactory)
{
_serviceScopeFactory = serviceScopeFactory;
_daoFactory = daoFactory;
}
public void InitJob(Tenant tenant)
{
TenantId = tenant.Id;
}
protected override void DoJob()
public async Task RunJobAsync(DistributedTask _, CancellationToken cancellationToken)
{
try
{
@ -117,6 +115,8 @@ public class UsersQuotaSyncJob : DistributedTaskProgress
var _authentication = scope.ServiceProvider.GetRequiredService<AuthManager>();
var _securityContext = scope.ServiceProvider.GetRequiredService<SecurityContext>();
var _webItemManagerSecurity = scope.ServiceProvider.GetRequiredService<WebItemManagerSecurity>();
_tenantManager.SetCurrentTenant(TenantId);
var users = _userManager.GetUsers();
var webItems = _webItemManagerSecurity.GetItems(Web.Core.WebZones.WebZoneType.All, ItemAvailableState.All);
@ -137,7 +137,7 @@ public class UsersQuotaSyncJob : DistributedTaskProgress
{
continue;
}
manager.RecalculateUserQuota(TenantId, user.Id);
await manager.RecalculateUserQuota(TenantId, user.Id);
}
}

View File

@ -44,5 +44,5 @@ public interface IUserSpaceUsage
{
Task<long> GetUserSpaceUsageAsync(Guid userId);
void RecalculateUserQuota(int tenantId, Guid userId);
Task RecalculateUserQuota(int tenantId, Guid userId);
}