Skip to content

Commit

Permalink
try alternate GetExistingRules() query
Browse files Browse the repository at this point in the history
  • Loading branch information
collinbarrett committed Aug 20, 2018
1 parent 7e85c96 commit 4a9bb07
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/FilterLists.Services/Snapshot/SnapshotBatch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FilterLists.Data;
Expand Down Expand Up @@ -33,23 +32,13 @@ public async Task SaveAsync()
await dbContext.SaveChangesAsync();
}

private IQueryable<Rule> GetExistingRules()
{
var lineRules = lines.Select(l => new Rule {Raw = l});
return dbContext.Rules.Intersect(lineRules, new RuleRawEqualityComparer());
}
private IQueryable<Rule> GetExistingRules() =>
dbContext.Rules.Join(lines, rule => rule.Raw, line => line, (rule, line) => rule);

private List<Rule> CreateNewRules(IQueryable<Rule> existingRules) =>
lines.Except(existingRules.Select(r => r.Raw)).Select(r => new Rule {Raw = r}).ToList();

private void AddSnapshotRules(IQueryable<Rule> rules) =>
snapEntity.AddedSnapshotRules.AddRange(rules.Select(r => new SnapshotRule {Rule = r}));

private class RuleRawEqualityComparer : IEqualityComparer<Rule>
{
public bool Equals(Rule x, Rule y) => x?.Raw == y?.Raw;

public int GetHashCode(Rule obj) => throw new NotImplementedException();
}
}
}

0 comments on commit 4a9bb07

Please sign in to comment.