forked from ddrilling/AsbCloudServer
refact
This commit is contained in:
parent
d35550380c
commit
f7a58cfa12
@ -1,6 +1,5 @@
|
||||
using AsbCloudDb.Model.Subsystems;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -363,7 +362,5 @@ namespace AsbCloudDb.Model
|
||||
var sql = $"REFRESH MATERIALIZED VIEW {materializedViewName};";
|
||||
return Database.ExecuteSqlRawAsync(sql, token);
|
||||
}
|
||||
|
||||
public ChangeTracker GetChangeTracker() => ChangeTracker;
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,5 @@ namespace AsbCloudDb.Model
|
||||
DbSet<TEntity> Set<TEntity>(string name) where TEntity : class;
|
||||
DbSet<TEntity> Set<TEntity>() where TEntity : class;
|
||||
EntityEntry<TEntity> Entry<TEntity>([NotNull] TEntity entity) where TEntity : class;
|
||||
ChangeTracker GetChangeTracker();
|
||||
|
||||
}
|
||||
}
|
@ -194,14 +194,6 @@ namespace AsbCloudInfrastructure.Repository
|
||||
{
|
||||
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()
|
||||
{
|
||||
var query = dbContext.RelationUserUserRoles
|
||||
@ -216,7 +208,7 @@ namespace AsbCloudInfrastructure.Repository
|
||||
|
||||
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);
|
||||
|
||||
if (newRoles?.Any() is true)
|
||||
@ -235,7 +227,6 @@ namespace AsbCloudInfrastructure.Repository
|
||||
{
|
||||
async Task<TEntity[]> factory(CancellationToken token)
|
||||
=> await query.ToArrayAsync(token);
|
||||
dbContext.GetChangeTracker().Clear();
|
||||
var cache = await GetOrAddCacheAsync(tag, factory, obsolescence, token);
|
||||
return cache.Select(convert);
|
||||
}
|
||||
@ -244,7 +235,6 @@ namespace AsbCloudInfrastructure.Repository
|
||||
{
|
||||
async Task<TEntity[]> factory(CancellationToken token)
|
||||
=> await query.ToArrayAsync(token);
|
||||
dbContext.GetChangeTracker().Clear();
|
||||
var cache = await GetOrAddCacheAsync(tag, factory, obsolescence, token);
|
||||
return cache;
|
||||
}
|
||||
@ -253,7 +243,6 @@ namespace AsbCloudInfrastructure.Repository
|
||||
{
|
||||
TEntity[] factory()
|
||||
=> query.ToArray();
|
||||
dbContext.GetChangeTracker().Clear();
|
||||
var cache = GetOrAddCache(tag, factory, obsolescence);
|
||||
return cache.Select(convert);
|
||||
}
|
||||
@ -262,7 +251,6 @@ namespace AsbCloudInfrastructure.Repository
|
||||
{
|
||||
TEntity[] factory()
|
||||
=> query.ToArray();
|
||||
dbContext.GetChangeTracker().Clear();
|
||||
var cache = GetOrAddCache(tag, factory, obsolescence);
|
||||
return cache;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user