From 7332a0ca84292aba92930a4c86ce3d29c683634f Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Thu, 1 Feb 2018 10:18:11 -0600 Subject: [PATCH] minor cleanup from last refactor --- src/FilterLists.Services/ScrapeService/ScrapeService.cs | 2 +- src/FilterLists.Services/ScrapeService/Snapshot.cs | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/FilterLists.Services/ScrapeService/ScrapeService.cs b/src/FilterLists.Services/ScrapeService/ScrapeService.cs index 1175c1671..ac89e7ffc 100644 --- a/src/FilterLists.Services/ScrapeService/ScrapeService.cs +++ b/src/FilterLists.Services/ScrapeService/ScrapeService.cs @@ -35,7 +35,7 @@ private async Task> GetNextListsToScrape(int batchSiz private async Task> GetSnapshots(IEnumerable lists) { return await Task.WhenAll(lists - .Select(async list => new Snapshot(dbContext, await TryGetContent(list.ViewUrl), list.Id)) + .Select(async list => new Snapshot(dbContext, list.Id, await TryGetContent(list.ViewUrl))) .Where(x => x.Result.HasRules)); } diff --git a/src/FilterLists.Services/ScrapeService/Snapshot.cs b/src/FilterLists.Services/ScrapeService/Snapshot.cs index 6b0f2ee74..0910dc93e 100644 --- a/src/FilterLists.Services/ScrapeService/Snapshot.cs +++ b/src/FilterLists.Services/ScrapeService/Snapshot.cs @@ -15,7 +15,7 @@ public class Snapshot private string[] rawRules; - public Snapshot(FilterListsDbContext dbContext, string content, int filterListId) + public Snapshot(FilterListsDbContext dbContext, int filterListId, string content) { this.dbContext = dbContext; this.filterListId = filterListId; @@ -40,12 +40,10 @@ public async Task AddOrUpdateRules() var preExistingSnapshotRules = dbContext.Rules.Where(x => rawRules.Contains(x.Raw)); var newSnapshotRawRules = rawRules.Except(preExistingSnapshotRules.Select(x => x.Raw)); var newSnapshotRules = newSnapshotRawRules.Select(newSnapshotRawRule => new Rule {Raw = newSnapshotRawRule}).ToList(); - dbContext.Rules.AddRange(newSnapshotRules); // remove deleted FilterListRules var preExistingFilterListRules = dbContext.FilterListRules.Where(x => x.FilterListId == filterListId); - var deletedFilterListRules = - preExistingFilterListRules.Where(x => !preExistingSnapshotRules.Select(y => y.Id).Contains(x.RuleId)); + var deletedFilterListRules = preExistingFilterListRules.Where(x => !preExistingSnapshotRules.Select(y => y.Id).Contains(x.RuleId)); // add FilterListRules for pre-existing Rules var preExistingSnapshotFilterListRules = preExistingSnapshotRules.Select(newSnapshotRule => @@ -64,7 +62,7 @@ public async Task AddOrUpdateRules() // update ScrapedDateUtc list.ScrapedDateUtc = DateTime.UtcNow; - + dbContext.Rules.AddRange(newSnapshotRules); dbContext.FilterListRules.RemoveRange(deletedFilterListRules); dbContext.FilterListRules.AddRange(preExistingSnapshotFilterListRules); dbContext.FilterListRules.AddRange(newFilterListRules);