From 4a9bb075d0c54a8a8212187b537fecb81b5c8167 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Mon, 20 Aug 2018 08:33:04 -0500 Subject: [PATCH] try alternate GetExistingRules() query per https://stackoverflow.com/a/51931004/2343739 ref #357 --- .../Snapshot/SnapshotBatch.cs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/FilterLists.Services/Snapshot/SnapshotBatch.cs b/src/FilterLists.Services/Snapshot/SnapshotBatch.cs index 2ac228517d..a1af7099e2 100644 --- a/src/FilterLists.Services/Snapshot/SnapshotBatch.cs +++ b/src/FilterLists.Services/Snapshot/SnapshotBatch.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using FilterLists.Data; @@ -33,23 +32,13 @@ public async Task SaveAsync() await dbContext.SaveChangesAsync(); } - private IQueryable GetExistingRules() - { - var lineRules = lines.Select(l => new Rule {Raw = l}); - return dbContext.Rules.Intersect(lineRules, new RuleRawEqualityComparer()); - } + private IQueryable GetExistingRules() => + dbContext.Rules.Join(lines, rule => rule.Raw, line => line, (rule, line) => rule); private List CreateNewRules(IQueryable existingRules) => lines.Except(existingRules.Select(r => r.Raw)).Select(r => new Rule {Raw = r}).ToList(); private void AddSnapshotRules(IQueryable rules) => snapEntity.AddedSnapshotRules.AddRange(rules.Select(r => new SnapshotRule {Rule = r})); - - private class RuleRawEqualityComparer : IEqualityComparer - { - public bool Equals(Rule x, Rule y) => x?.Raw == y?.Raw; - - public int GetHashCode(Rule obj) => throw new NotImplementedException(); - } } } \ No newline at end of file