From b202501011b7edb0b3ddeca5ff7cfb14b11ca8c8 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Sat, 8 Sep 2018 12:06:47 -0500 Subject: [PATCH] re-write CleanupFailedSnapshots() closes #437 --- src/FilterLists.Services/Snapshot/SnapshotService.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/FilterLists.Services/Snapshot/SnapshotService.cs b/src/FilterLists.Services/Snapshot/SnapshotService.cs index 66366bf98..2a84e280e 100644 --- a/src/FilterLists.Services/Snapshot/SnapshotService.cs +++ b/src/FilterLists.Services/Snapshot/SnapshotService.cs @@ -33,7 +33,7 @@ public SnapshotService(FilterListsDbContext dbContext, IConfigurationProvider ma public async Task CaptureAsync(int batchSize) { - //await CleanupFailedSnapshots(); + await CleanupFailedSnapshots(); uaString = await UserAgentService.GetMostPopularString(); var lists = await GetListsToCapture(batchSize); var snaps = await CreateAndSaveSnaps(lists); @@ -41,11 +41,14 @@ public async Task CaptureAsync(int batchSize) await CreateAndSaveSnaps(listsToRetry); } - //TODO: speed this up, too slow, loads all into memory private async Task CleanupFailedSnapshots() { - DbContext.RemoveRange(DbContext.SnapshotRules.Where(sr => !sr.Snapshot.WasSuccessful)); - await DbContext.SaveChangesAsync(); + const string command = + @"DELETE snapshots_rules + FROM snapshots_rules + JOIN snapshots ON snapshots.Id = snapshots_rules.SnapshotId + WHERE snapshots.WasSuccessful = 0;"; + await DbContext.Database.ExecuteSqlCommandAsync(command); } private async Task> GetListsToCapture(int batchSize) =>