diff --git a/src/FilterLists.Services/Snapshot/SnapshotBatch.cs b/src/FilterLists.Services/Snapshot/SnapshotBatch.cs index 0b2f4cfb8..2ac228517 100644 --- a/src/FilterLists.Services/Snapshot/SnapshotBatch.cs +++ b/src/FilterLists.Services/Snapshot/SnapshotBatch.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using FilterLists.Data; @@ -32,12 +33,23 @@ public async Task SaveAsync() await dbContext.SaveChangesAsync(); } - private IQueryable GetExistingRules() => dbContext.Rules.Where(r => lines.Contains(r.Raw)); + private IQueryable GetExistingRules() + { + var lineRules = lines.Select(l => new Rule {Raw = l}); + return dbContext.Rules.Intersect(lineRules, new RuleRawEqualityComparer()); + } 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