re-write CleanupFailedSnapshots()

closes #437
This commit is contained in:
Collin M. Barrett 2018-09-08 12:06:47 -05:00
parent fe8927064f
commit b202501011

View file

@ -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<Snapshot>(lists);
@ -41,11 +41,14 @@ public async Task CaptureAsync(int batchSize)
await CreateAndSaveSnaps<SnapshotWayback>(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<IEnumerable<FilterListViewUrlDto>> GetListsToCapture(int batchSize) =>