From d566db9e59c42f29f03fbc7df486d4db2cc2b07f Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Mon, 20 Aug 2018 13:20:36 -0500 Subject: [PATCH] try making batch saves non-async ref #357 --- src/FilterLists.Services/Snapshot/Snapshot.cs | 10 +++++----- src/FilterLists.Services/Snapshot/SnapshotBatch.cs | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/FilterLists.Services/Snapshot/Snapshot.cs b/src/FilterLists.Services/Snapshot/Snapshot.cs index e2857cf11..e2c8605a1 100644 --- a/src/FilterLists.Services/Snapshot/Snapshot.cs +++ b/src/FilterLists.Services/Snapshot/Snapshot.cs @@ -59,7 +59,7 @@ private async Task SaveAsync() var lines = await TryGetLines(); if (lines != null) { - await SaveInBatches(lines); + SaveInBatches(lines); await DedupSnapshotRules(); await SetSuccessful(); } @@ -105,19 +105,19 @@ private async Task> GetLines() return lines; } - private async Task SaveInBatches(IEnumerable lines) + private void SaveInBatches(IEnumerable lines) { var snapshotBatches = CreateBatches(lines); - await SaveBatches(snapshotBatches); + SaveBatches(snapshotBatches); } private IEnumerable CreateBatches(IEnumerable lines) => lines.Batch(BatchSize).Select(b => new SnapshotBatch(dbContext, b, snapEntity)); - private static async Task SaveBatches(IEnumerable batches) + private static void SaveBatches(IEnumerable batches) { foreach (var batch in batches) - await batch.SaveAsync(); + batch.Save(); } private async Task DedupSnapshotRules() diff --git a/src/FilterLists.Services/Snapshot/SnapshotBatch.cs b/src/FilterLists.Services/Snapshot/SnapshotBatch.cs index 6272480b4..2244a3181 100644 --- a/src/FilterLists.Services/Snapshot/SnapshotBatch.cs +++ b/src/FilterLists.Services/Snapshot/SnapshotBatch.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using FilterLists.Data; using FilterLists.Data.Entities; using FilterLists.Data.Entities.Junctions; @@ -22,14 +21,14 @@ public SnapshotBatch(FilterListsDbContext dbContext, IEnumerable lines, this.snapEntity = snapEntity; } - public async Task SaveAsync() + public void Save() { var existingRules = GetExistingRules(); var newRules = CreateNewRules(existingRules); dbContext.Rules.AddRange(newRules); var rules = existingRules.Concat(newRules); AddSnapshotRules(rules); - await dbContext.SaveChangesAsync(); + dbContext.SaveChanges(); } private IQueryable GetExistingRules() =>