From c1772a868054aafdcbd390d82eaaeb7a09f51fe2 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Mon, 29 Jan 2018 15:24:02 -0600 Subject: [PATCH] move rule parsing to Snapshot class --- .../Services/ScrapeService.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/FilterLists.Services/Services/ScrapeService.cs b/src/FilterLists.Services/Services/ScrapeService.cs index 6f839a2cb..aa996c682 100644 --- a/src/FilterLists.Services/Services/ScrapeService.cs +++ b/src/FilterLists.Services/Services/ScrapeService.cs @@ -70,10 +70,9 @@ private void AddOrUpdateRules(IEnumerable snapshots) private void AddOrUpdateRules(Snapshot snapshot) { // add new Rules - var snapshotRulesRaw = - snapshot.Content.Split(new[] {"\r\n", "\r", "\n"}, StringSplitOptions.RemoveEmptyEntries); - var preExistingSnapshotRules = filterListsDbContext.Rules.Where(x => snapshotRulesRaw.Contains(x.Raw)); - var newSnapshotRulesRaw = snapshotRulesRaw.Except(preExistingSnapshotRules.Select(x => x.Raw)); + snapshot.ParseRawRules(); + var preExistingSnapshotRules = filterListsDbContext.Rules.Where(x => snapshot.RawRules.Contains(x.Raw)); + var newSnapshotRulesRaw = snapshot.RawRules.Except(preExistingSnapshotRules.Select(x => x.Raw)); var newSnapshotRules = newSnapshotRulesRaw.Select(newSnapshotRuleRaw => new Rule {Raw = newSnapshotRuleRaw}); filterListsDbContext.Rules.AddRange(newSnapshotRules); @@ -109,8 +108,14 @@ private class FilterListDto private class Snapshot { - public string Content { get; set; } + public string Content { private get; set; } public int FilterListId { get; set; } + public string[] RawRules { get; private set; } + + public void ParseRawRules() + { + RawRules = Content.Split(new[] {"\r\n", "\r", "\n"}, StringSplitOptions.RemoveEmptyEntries); + } } } } \ No newline at end of file