mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
extract base service, add RuleService.GetCountAllActiveRules()
This commit is contained in:
parent
161a5181de
commit
d1601ff7aa
5 changed files with 72 additions and 38 deletions
|
|
@ -9,29 +9,27 @@
|
|||
namespace FilterLists.Services.FilterList
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class FilterListService
|
||||
public class FilterListService : Service
|
||||
{
|
||||
private readonly FilterListsDbContext _filterListsDbContext;
|
||||
|
||||
public FilterListService(FilterListsDbContext filterListsDbContext)
|
||||
public FilterListService(FilterListsDbContext dbContext) : base(dbContext)
|
||||
{
|
||||
_filterListsDbContext = filterListsDbContext;
|
||||
DbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ListSummaryDto>> GetAllSummariesAsync()
|
||||
{
|
||||
return await _filterListsDbContext.FilterLists.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.ProjectTo<ListSummaryDto>()
|
||||
.ToListAsync();
|
||||
return await DbContext.FilterLists.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.ProjectTo<ListSummaryDto>()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<ListDetailsDto> GetDetailsAsync(int id)
|
||||
{
|
||||
return await _filterListsDbContext.FilterLists.AsNoTracking()
|
||||
.ProjectTo<ListDetailsDto>()
|
||||
.FirstAsync(x => x.Id == id)
|
||||
.FilterParentListFromMaintainerAdditionalLists();
|
||||
return await DbContext.FilterLists.AsNoTracking()
|
||||
.ProjectTo<ListDetailsDto>()
|
||||
.FirstAsync(x => x.Id == id)
|
||||
.FilterParentListFromMaintainerAdditionalLists();
|
||||
}
|
||||
}
|
||||
}
|
||||
23
src/FilterLists.Services/RuleService.cs
Normal file
23
src/FilterLists.Services/RuleService.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Data;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FilterLists.Services
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class RuleService : Service
|
||||
{
|
||||
public RuleService(FilterListsDbContext dbContext) : base(dbContext)
|
||||
{
|
||||
DbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<int> GetCountAllActiveRules() => await DbContext
|
||||
.SnapshotRules.AsNoTracking()
|
||||
.Where(x => x.RemovedBySnapshotId == null)
|
||||
.GroupBy(x => x.RuleId)
|
||||
.CountAsync();
|
||||
}
|
||||
}
|
||||
|
|
@ -10,37 +10,35 @@
|
|||
namespace FilterLists.Services.Seed
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SeedService
|
||||
public class SeedService : Service
|
||||
{
|
||||
private readonly FilterListsDbContext _filterListsDbContext;
|
||||
|
||||
public SeedService(FilterListsDbContext filterListsDbContext)
|
||||
public SeedService(FilterListsDbContext dbContext) : base(dbContext)
|
||||
{
|
||||
_filterListsDbContext = filterListsDbContext;
|
||||
DbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TSeedDto>> GetAllAsync<TEntity, TSeedDto>() where TEntity : class =>
|
||||
await _filterListsDbContext.Set<TEntity>().AsNoTracking().ProjectTo<TSeedDto>().ToArrayAsync();
|
||||
await DbContext.Set<TEntity>().AsNoTracking().ProjectTo<TSeedDto>().ToArrayAsync();
|
||||
|
||||
public async Task<IEnumerable<TSeedDto>> GetAllAsync<TEntity, TSeedDto>(PropertyInfo primarySort)
|
||||
where TEntity : class
|
||||
{
|
||||
return await _filterListsDbContext.Set<TEntity>()
|
||||
.OrderBy(x => primarySort.GetValue(x, null))
|
||||
.AsNoTracking()
|
||||
.ProjectTo<TSeedDto>()
|
||||
.ToArrayAsync();
|
||||
return await DbContext.Set<TEntity>()
|
||||
.OrderBy(x => primarySort.GetValue(x, null))
|
||||
.AsNoTracking()
|
||||
.ProjectTo<TSeedDto>()
|
||||
.ToArrayAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TSeedDto>> GetAllAsync<TEntity, TSeedDto>(PropertyInfo primarySort,
|
||||
PropertyInfo secondarySort) where TEntity : class
|
||||
{
|
||||
return await _filterListsDbContext.Set<TEntity>()
|
||||
.OrderBy(x => primarySort.GetValue(x, null))
|
||||
.ThenBy(x => secondarySort.GetValue(x, null))
|
||||
.AsNoTracking()
|
||||
.ProjectTo<TSeedDto>()
|
||||
.ToArrayAsync();
|
||||
return await DbContext.Set<TEntity>()
|
||||
.OrderBy(x => primarySort.GetValue(x, null))
|
||||
.ThenBy(x => secondarySort.GetValue(x, null))
|
||||
.AsNoTracking()
|
||||
.ProjectTo<TSeedDto>()
|
||||
.ToArrayAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
16
src/FilterLists.Services/Service.cs
Normal file
16
src/FilterLists.Services/Service.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using FilterLists.Data;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Services
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class Service
|
||||
{
|
||||
protected FilterListsDbContext DbContext;
|
||||
|
||||
public Service(FilterListsDbContext dbContext)
|
||||
{
|
||||
DbContext = dbContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,15 +10,14 @@
|
|||
namespace FilterLists.Services.Snapshot
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SnapshotService
|
||||
public class SnapshotService : Service
|
||||
{
|
||||
//TODO: update algorithm to support non-standard list sizes and formats (#200, #201)
|
||||
private readonly List<int> _ignoreLists = new List<int> {48, 149, 173, 185, 186, 187, 188, 189, 352};
|
||||
private readonly FilterListsDbContext dbContext;
|
||||
|
||||
public SnapshotService(FilterListsDbContext dbContext)
|
||||
public SnapshotService(FilterListsDbContext dbContext) : base(dbContext)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
DbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task CaptureAsync(int batchSize)
|
||||
|
|
@ -31,14 +30,14 @@ public async Task CaptureAsync(int batchSize)
|
|||
|
||||
private void RollbackIncompletedSnapshots()
|
||||
{
|
||||
var incompleteSnapshots = dbContext.Snapshots.Where(ss => ss.IsCompleted == false);
|
||||
dbContext.Snapshots.RemoveRange(incompleteSnapshots);
|
||||
var incompleteSnapshots = DbContext.Snapshots.Where(ss => ss.IsCompleted == false);
|
||||
DbContext.Snapshots.RemoveRange(incompleteSnapshots);
|
||||
//TODO: don't assume that SnapshotDe.DedupSnapshotRules() didn't partially complete
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<FilterListViewUrlDto>> GetListsToCapture(int batchSize)
|
||||
{
|
||||
return await dbContext
|
||||
return await DbContext
|
||||
.FilterLists
|
||||
.Where(list =>
|
||||
(!list.Snapshots.Any() ||
|
||||
|
|
@ -58,7 +57,7 @@ private async Task<IEnumerable<FilterListViewUrlDto>> GetListsToCapture(int batc
|
|||
|
||||
private IEnumerable<SnapshotDe> GetSnapshots(IEnumerable<FilterListViewUrlDto> lists)
|
||||
{
|
||||
return lists.Select(list => new SnapshotDe(dbContext, list));
|
||||
return lists.Select(list => new SnapshotDe(DbContext, list));
|
||||
}
|
||||
|
||||
private static async Task SaveSnapshots(IEnumerable<SnapshotDe> snapshots)
|
||||
|
|
|
|||
Loading…
Reference in a new issue