mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
async batches
This commit is contained in:
parent
ad0ab03b77
commit
ee09614db4
2 changed files with 9 additions and 8 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Data;
|
||||
using FilterLists.Data.Entities;
|
||||
using FilterLists.Data.Entities.Junctions;
|
||||
|
|
@ -22,11 +23,11 @@ public SnapshotBatchDe(FilterListsDbContext dbContext, Snapshot snapshot, IEnume
|
|||
this.rawRules = rawRules;
|
||||
}
|
||||
|
||||
public void SaveSnapshotBatch()
|
||||
public async Task SaveSnapshotBatchAsync()
|
||||
{
|
||||
AddNewRules();
|
||||
AddSnapshotRules();
|
||||
dbContext.SaveChanges();
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private void AddNewRules()
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public async Task SaveSnapshotAsync()
|
|||
var content = await TryGetContent();
|
||||
await dbContext.SaveChangesAsync();
|
||||
if (content != null)
|
||||
SaveSnapshotInBatches(content);
|
||||
await SaveSnapshotInBatches(content);
|
||||
}
|
||||
|
||||
private async Task AddSnapshot()
|
||||
|
|
@ -69,11 +69,11 @@ private async Task<string> GetContent()
|
|||
return null;
|
||||
}
|
||||
|
||||
private void SaveSnapshotInBatches(string content)
|
||||
private async Task SaveSnapshotInBatches(string content)
|
||||
{
|
||||
var rawRules = GetRawRules(content);
|
||||
var snapshotBatches = GetSnapshotBatches(rawRules);
|
||||
SaveSnapshotBatches(snapshotBatches);
|
||||
await SaveSnapshotBatches(snapshotBatches);
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetRawRules(string content)
|
||||
|
|
@ -81,7 +81,7 @@ private static IEnumerable<string> GetRawRules(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].LintStringForMySql();
|
||||
return new HashSet<string>(rawRules);
|
||||
return new HashSet<string>(rawRules.Where(x => x != null));
|
||||
}
|
||||
|
||||
private IEnumerable<SnapshotBatchDe> GetSnapshotBatches(IEnumerable<string> rawRules)
|
||||
|
|
@ -90,10 +90,10 @@ private IEnumerable<SnapshotBatchDe> GetSnapshotBatches(IEnumerable<string> rawR
|
|||
.Select(rawRuleBatch => new SnapshotBatchDe(dbContext, snapshot, rawRuleBatch));
|
||||
}
|
||||
|
||||
private static void SaveSnapshotBatches(IEnumerable<SnapshotBatchDe> snapshotBatches)
|
||||
private static async Task SaveSnapshotBatches(IEnumerable<SnapshotBatchDe> snapshotBatches)
|
||||
{
|
||||
foreach (var snapshotBatch in snapshotBatches)
|
||||
snapshotBatch.SaveSnapshotBatch();
|
||||
await snapshotBatch.SaveSnapshotBatchAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue