mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
remove AsNoTracking() from ProjectTo() chains
This commit is contained in:
parent
7b325e5000
commit
d749ef3016
3 changed files with 33 additions and 56 deletions
|
|
@ -38,19 +38,13 @@ public async Task<IEnumerable<ListSummaryDto>> GetAllSummariesAsync()
|
|||
});
|
||||
}
|
||||
|
||||
private async Task<List<ListSummaryDto>> GetSummaryDtos()
|
||||
{
|
||||
return await DbContext.FilterLists.AsNoTracking()
|
||||
.OrderBy(l => l.Name)
|
||||
.ProjectTo<ListSummaryDto>()
|
||||
.ToListAsync();
|
||||
}
|
||||
private async Task<List<ListSummaryDto>> GetSummaryDtos() =>
|
||||
await DbContext.FilterLists.OrderBy(l => l.Name).ProjectTo<ListSummaryDto>().ToListAsync();
|
||||
|
||||
private async Task<List<Data.Entities.Snapshot>> GetLatestSnapshots()
|
||||
{
|
||||
return await DbContext.Snapshots.AsNoTracking()
|
||||
.Where(s => s.IsCompleted &&
|
||||
s.HttpStatusCode == "200" &&
|
||||
.Where(s => s.IsCompleted && s.HttpStatusCode == "200" &&
|
||||
(s.AddedSnapshotRules.Count > 0 || s.RemovedSnapshotRules.Count > 0))
|
||||
.GroupBy(s => s.FilterListId,
|
||||
(key, x) => x.OrderByDescending(y => y.CreatedDateUtc).First())
|
||||
|
|
@ -59,8 +53,7 @@ private async Task<List<ListSummaryDto>> GetSummaryDtos()
|
|||
|
||||
public async Task<ListDetailsDto> GetDetailsAsync(uint id)
|
||||
{
|
||||
var details = await DbContext.FilterLists.AsNoTracking()
|
||||
.ProjectTo<ListDetailsDto>()
|
||||
var details = await DbContext.FilterLists.ProjectTo<ListDetailsDto>()
|
||||
.FirstAsync(x => x.Id == id)
|
||||
.FilterParentListFromMaintainerAdditionalLists();
|
||||
details.RuleCount = await GetActiveRuleCount(details);
|
||||
|
|
@ -79,8 +72,7 @@ private async Task<int> GetActiveRuleCount(ListDetailsDto details)
|
|||
private async Task<DateTime?> GetUpdatedDate(ListDetailsDto details)
|
||||
{
|
||||
var snapshotDates = DbContext.Snapshots.AsNoTracking()
|
||||
.Where(s => s.FilterListId == details.Id &&
|
||||
s.IsCompleted &&
|
||||
.Where(s => s.FilterListId == details.Id && s.IsCompleted &&
|
||||
s.HttpStatusCode == "200" &&
|
||||
(s.AddedSnapshotRules.Count > 0 ||
|
||||
s.RemovedSnapshotRules.Count > 0))
|
||||
|
|
|
|||
|
|
@ -18,27 +18,20 @@ public SeedService(FilterListsDbContext dbContext) : base(dbContext)
|
|||
}
|
||||
|
||||
public async Task<IEnumerable<TSeedDto>> GetAllAsync<TEntity, TSeedDto>() where TEntity : class =>
|
||||
await DbContext.Set<TEntity>().AsNoTracking().ProjectTo<TSeedDto>().ToArrayAsync();
|
||||
await DbContext.Set<TEntity>().ProjectTo<TSeedDto>().ToArrayAsync();
|
||||
|
||||
public async Task<IEnumerable<TSeedDto>> GetAllAsync<TEntity, TSeedDto>(PropertyInfo primarySort)
|
||||
where TEntity : class
|
||||
{
|
||||
return await DbContext.Set<TEntity>()
|
||||
.OrderBy(x => primarySort.GetValue(x, null))
|
||||
.AsNoTracking()
|
||||
.ProjectTo<TSeedDto>()
|
||||
.ToArrayAsync();
|
||||
}
|
||||
where TEntity : class => await DbContext.Set<TEntity>()
|
||||
.OrderBy(x => primarySort.GetValue(x, null))
|
||||
.ProjectTo<TSeedDto>()
|
||||
.ToArrayAsync();
|
||||
|
||||
public async Task<IEnumerable<TSeedDto>> GetAllAsync<TEntity, TSeedDto>(PropertyInfo primarySort,
|
||||
PropertyInfo secondarySort) where TEntity : class
|
||||
{
|
||||
return await DbContext.Set<TEntity>()
|
||||
.OrderBy(x => primarySort.GetValue(x, null))
|
||||
.ThenBy(x => secondarySort.GetValue(x, null))
|
||||
.AsNoTracking()
|
||||
.ProjectTo<TSeedDto>()
|
||||
.ToArrayAsync();
|
||||
}
|
||||
public async Task<IEnumerable<TSeedDto>>
|
||||
GetAllAsync<TEntity, TSeedDto>(PropertyInfo primarySort, PropertyInfo secondarySort)
|
||||
where TEntity : class => await DbContext.Set<TEntity>()
|
||||
.OrderBy(x => primarySort.GetValue(x, null))
|
||||
.ThenBy(x => secondarySort.GetValue(x, null))
|
||||
.ProjectTo<TSeedDto>()
|
||||
.ToArrayAsync();
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ namespace FilterLists.Services.Snapshot
|
|||
public class SnapshotService : Service
|
||||
{
|
||||
//TODO: update algorithm to support non-standard list sizes and formats (#200, #201)
|
||||
private readonly List<uint> _ignoreLists = new List<uint> {48, 149, 173, 185, 186, 187, 188, 189, 352};
|
||||
private readonly List<uint> ignoreLists = new List<uint> {48, 149, 173, 185, 186, 187, 188, 189, 352};
|
||||
|
||||
public SnapshotService(FilterListsDbContext dbContext) : base(dbContext)
|
||||
{
|
||||
|
|
@ -35,30 +35,22 @@ private void RollbackIncompletedSnapshots()
|
|||
//TODO: don't assume that SnapshotDe.DedupSnapshotRules() didn't partially complete
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<FilterListViewUrlDto>> GetListsToCapture(int batchSize)
|
||||
{
|
||||
return await DbContext
|
||||
.FilterLists
|
||||
.Where(list =>
|
||||
(!list.Snapshots.Any() ||
|
||||
list.Snapshots.Select(ss => ss.CreatedDateUtc)
|
||||
.OrderByDescending(sscd => sscd)
|
||||
.FirstOrDefault() < DateTime.UtcNow.AddDays(-1)) && !_ignoreLists.Contains(list.Id))
|
||||
.OrderBy(list => list.Snapshots.Any())
|
||||
.ThenBy(list =>
|
||||
list.Snapshots.Select(ss => ss.CreatedDateUtc)
|
||||
.OrderByDescending(sscd => sscd)
|
||||
.FirstOrDefault())
|
||||
.Take(batchSize)
|
||||
.AsNoTracking()
|
||||
.ProjectTo<FilterListViewUrlDto>()
|
||||
.ToListAsync();
|
||||
}
|
||||
private async Task<IEnumerable<FilterListViewUrlDto>> GetListsToCapture(int batchSize) =>
|
||||
await DbContext
|
||||
.FilterLists
|
||||
.Where(list =>
|
||||
(!list.Snapshots.Any() ||
|
||||
list.Snapshots.Select(ss => ss.CreatedDateUtc).OrderByDescending(sscd => sscd).FirstOrDefault() <
|
||||
DateTime.UtcNow.AddDays(-1)) && !ignoreLists.Contains(list.Id))
|
||||
.OrderBy(list => list.Snapshots.Any())
|
||||
.ThenBy(list =>
|
||||
list.Snapshots.Select(ss => ss.CreatedDateUtc).OrderByDescending(sscd => sscd).FirstOrDefault())
|
||||
.Take(batchSize)
|
||||
.ProjectTo<FilterListViewUrlDto>()
|
||||
.ToListAsync();
|
||||
|
||||
private IEnumerable<SnapshotDe> GetSnapshots(IEnumerable<FilterListViewUrlDto> lists)
|
||||
{
|
||||
return lists.Select(list => new SnapshotDe(DbContext, list));
|
||||
}
|
||||
private IEnumerable<SnapshotDe> GetSnapshots(IEnumerable<FilterListViewUrlDto> lists) =>
|
||||
lists.Select(list => new SnapshotDe(DbContext, list));
|
||||
|
||||
private static async Task SaveSnapshots(IEnumerable<SnapshotDe> snapshots)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue