mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
parent
5adb37033a
commit
740da95e1b
3 changed files with 11 additions and 13 deletions
|
|
@ -29,4 +29,8 @@
|
|||
<ProjectReference Include="..\FilterLists.Data\FilterLists.Data.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Extensions\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -13,7 +13,7 @@ namespace FilterLists.Services.Snapshot
|
|||
{
|
||||
public class Snapshot
|
||||
{
|
||||
private const int BatchSize = 50;
|
||||
private const int BatchSize = 1000;
|
||||
private readonly FilterListsDbContext dbContext;
|
||||
private readonly FilterListViewUrlDto list;
|
||||
private readonly Data.Entities.Snapshot snapEntity;
|
||||
|
|
@ -104,7 +104,7 @@ private static IEnumerable<string> ParseRawRules(string content)
|
|||
var rawRules = content.Split(new[] {"\r\n", "\r", "\n"}, StringSplitOptions.RemoveEmptyEntries);
|
||||
for (var i = 0; i < rawRules.Length; i++)
|
||||
rawRules[i] = rawRules[i].LintRawRule();
|
||||
return rawRules.Where(r => r != null);
|
||||
return new HashSet<string>(rawRules.Where(r => r != null));
|
||||
}
|
||||
|
||||
private IEnumerable<SnapshotBatch> CreateBatches(IEnumerable<string> rawRules) =>
|
||||
|
|
|
|||
|
|
@ -13,29 +13,23 @@ public class SnapshotBatch
|
|||
private readonly FilterListsDbContext dbContext;
|
||||
private readonly IEnumerable<string> rawRules;
|
||||
private readonly Data.Entities.Snapshot snapEntity;
|
||||
private IQueryable<Rule> rules;
|
||||
|
||||
public SnapshotBatch(FilterListsDbContext dbContext, IEnumerable<string> rawRules,
|
||||
Data.Entities.Snapshot snapEntity)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
this.snapEntity = snapEntity;
|
||||
this.rawRules = rawRules;
|
||||
this.snapEntity = snapEntity;
|
||||
}
|
||||
|
||||
public async Task SaveAsync()
|
||||
{
|
||||
AddRules();
|
||||
AddSnapshotRules();
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private void AddRules()
|
||||
{
|
||||
var existingRules = GetExistingRules();
|
||||
var newRules = CreateNewRules(existingRules);
|
||||
rules = existingRules.Concat(newRules);
|
||||
dbContext.Rules.AddRange(newRules);
|
||||
var rules = existingRules.Concat(newRules);
|
||||
AddSnapshotRules(rules);
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private IQueryable<Rule> GetExistingRules() => dbContext.Rules.Where(r => rawRules.Contains(r.Raw));
|
||||
|
|
@ -43,7 +37,7 @@ private void AddRules()
|
|||
private List<Rule> CreateNewRules(IQueryable<Rule> existingRules) =>
|
||||
rawRules.Except(existingRules.Select(r => r.Raw)).Select(r => new Rule {Raw = r}).ToList();
|
||||
|
||||
private void AddSnapshotRules() =>
|
||||
private void AddSnapshotRules(IQueryable<Rule> rules) =>
|
||||
snapEntity.AddedSnapshotRules.AddRange(rules.Select(r => new SnapshotRule {Rule = r}));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue