mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
try alternate GetExistingRules() query
per https://stackoverflow.com/a/51931004/2343739 ref #357
This commit is contained in:
parent
7e85c96b65
commit
4a9bb075d0
1 changed files with 3 additions and 14 deletions
|
|
@ -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<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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue