This commit is contained in:
eugeniy_ivanov 2023-02-09 11:38:04 +05:00
parent d35550380c
commit f7a58cfa12
3 changed files with 2 additions and 19 deletions

View File

@ -1,6 +1,5 @@
using AsbCloudDb.Model.Subsystems; using AsbCloudDb.Model.Subsystems;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -362,8 +361,6 @@ namespace AsbCloudDb.Model
{ {
var sql = $"REFRESH MATERIALIZED VIEW {materializedViewName};"; var sql = $"REFRESH MATERIALIZED VIEW {materializedViewName};";
return Database.ExecuteSqlRawAsync(sql, token); return Database.ExecuteSqlRawAsync(sql, token);
} }
public ChangeTracker GetChangeTracker() => ChangeTracker;
} }
} }

View File

@ -73,7 +73,5 @@ namespace AsbCloudDb.Model
DbSet<TEntity> Set<TEntity>(string name) where TEntity : class; DbSet<TEntity> Set<TEntity>(string name) where TEntity : class;
DbSet<TEntity> Set<TEntity>() where TEntity : class; DbSet<TEntity> Set<TEntity>() where TEntity : class;
EntityEntry<TEntity> Entry<TEntity>([NotNull] TEntity entity) where TEntity : class; EntityEntry<TEntity> Entry<TEntity>([NotNull] TEntity entity) where TEntity : class;
ChangeTracker GetChangeTracker();
} }
} }

View File

@ -194,14 +194,6 @@ namespace AsbCloudInfrastructure.Repository
{ {
memoryCache.Remove(userCacheTag); memoryCache.Remove(userCacheTag);
} }
private async Task<IEnumerable<RelationUserUserRole>> GetCacheRelationUserUserRoleAsync(CancellationToken token)
{
var query = dbContext.RelationUserUserRoles
.Include(r => r.UserRole)
.Include(r => r.User);
return await FromCacheAsync(query, relationUserUserRoleCacheTag, cacheObsolence, token);
}
private IEnumerable<RelationUserUserRole> GetCachRelationUserUserRoleCacheTag() private IEnumerable<RelationUserUserRole> GetCachRelationUserUserRoleCacheTag()
{ {
var query = dbContext.RelationUserUserRoles var query = dbContext.RelationUserUserRoles
@ -216,7 +208,7 @@ namespace AsbCloudInfrastructure.Repository
private async Task UpdateRolesCacheForUserAsync(int idUser, IEnumerable<UserRoleDto> newRoles, CancellationToken token) private async Task UpdateRolesCacheForUserAsync(int idUser, IEnumerable<UserRoleDto> newRoles, CancellationToken token)
{ {
var relations = (await GetCacheRelationUserUserRoleAsync(token)).Where(r => r.IdUser == idUser); var relations = dbContext.RelationUserUserRoles.Where(r => r.IdUser == idUser);
dbContext.RelationUserUserRoles.RemoveRange(relations); dbContext.RelationUserUserRoles.RemoveRange(relations);
if (newRoles?.Any() is true) if (newRoles?.Any() is true)
@ -235,7 +227,6 @@ namespace AsbCloudInfrastructure.Repository
{ {
async Task<TEntity[]> factory(CancellationToken token) async Task<TEntity[]> factory(CancellationToken token)
=> await query.ToArrayAsync(token); => await query.ToArrayAsync(token);
dbContext.GetChangeTracker().Clear();
var cache = await GetOrAddCacheAsync(tag, factory, obsolescence, token); var cache = await GetOrAddCacheAsync(tag, factory, obsolescence, token);
return cache.Select(convert); return cache.Select(convert);
} }
@ -244,7 +235,6 @@ namespace AsbCloudInfrastructure.Repository
{ {
async Task<TEntity[]> factory(CancellationToken token) async Task<TEntity[]> factory(CancellationToken token)
=> await query.ToArrayAsync(token); => await query.ToArrayAsync(token);
dbContext.GetChangeTracker().Clear();
var cache = await GetOrAddCacheAsync(tag, factory, obsolescence, token); var cache = await GetOrAddCacheAsync(tag, factory, obsolescence, token);
return cache; return cache;
} }
@ -253,7 +243,6 @@ namespace AsbCloudInfrastructure.Repository
{ {
TEntity[] factory() TEntity[] factory()
=> query.ToArray(); => query.ToArray();
dbContext.GetChangeTracker().Clear();
var cache = GetOrAddCache(tag, factory, obsolescence); var cache = GetOrAddCache(tag, factory, obsolescence);
return cache.Select(convert); return cache.Select(convert);
} }
@ -262,7 +251,6 @@ namespace AsbCloudInfrastructure.Repository
{ {
TEntity[] factory() TEntity[] factory()
=> query.ToArray(); => query.ToArray();
dbContext.GetChangeTracker().Clear();
var cache = GetOrAddCache(tag, factory, obsolescence); var cache = GetOrAddCache(tag, factory, obsolescence);
return cache; return cache;
} }