fix CachedQuotaService.cs

This commit is contained in:
Anton Suhorukov 2023-04-07 11:06:18 +03:00
parent 11f32720a6
commit dec0d918d4

View File

@ -24,8 +24,6 @@
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 // content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode // International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
using ASC.Core.Billing;
namespace ASC.Core.Caching; namespace ASC.Core.Caching;
[Singletone] [Singletone]
@ -94,22 +92,16 @@ class CachedQuotaService : IQuotaService
var quotas = Cache.Get<IEnumerable<TenantQuota>>(QuotaServiceCache.KeyQuota); var quotas = Cache.Get<IEnumerable<TenantQuota>>(QuotaServiceCache.KeyQuota);
if (quotas == null) if (quotas == null)
{ {
return await GetTenantQuotasInternalAsync(); quotas = await Service.GetTenantQuotasAsync();
if (QuotaServiceCache.QuotaCacheEnabled)
{
Cache.Insert(QuotaServiceCache.KeyQuota, quotas, DateTime.UtcNow.Add(_cacheExpiration));
}
} }
return quotas; return quotas;
} }
private async Task<IEnumerable<TenantQuota>> GetTenantQuotasInternalAsync()
{
var quotas = await Service.GetTenantQuotasAsync();
if (QuotaServiceCache.QuotaCacheEnabled)
{
Cache.Insert(QuotaServiceCache.KeyQuota, quotas, DateTime.UtcNow.Add(_cacheExpiration));
}
return quotas;
}
public async Task<TenantQuota> GetTenantQuotaAsync(int tenant) public async Task<TenantQuota> GetTenantQuotaAsync(int tenant)
{ {
return (await GetTenantQuotasAsync()).SingleOrDefault(q => q.Tenant == tenant); return (await GetTenantQuotasAsync()).SingleOrDefault(q => q.Tenant == tenant);