mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
cleanup orphaned rules, reduce RulesCount complexity
This commit is contained in:
parent
44a2dd2e95
commit
514a03e9cf
2 changed files with 18 additions and 3 deletions
|
|
@ -1,5 +1,4 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Data;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
|
@ -14,6 +13,6 @@ public RuleService(FilterListsDbContext dbContext) : base(dbContext)
|
|||
}
|
||||
|
||||
public async Task<int> GetCountAll() =>
|
||||
await DbContext.Rules.AsNoTracking().Where(r => r.SnapshotRules.Any()).CountAsync();
|
||||
await DbContext.Rules.AsNoTracking().CountAsync();
|
||||
}
|
||||
}
|
||||
|
|
@ -36,6 +36,12 @@ public async Task CaptureAsync(int batchSize)
|
|||
}
|
||||
|
||||
private async Task CleanupFailedSnapshots()
|
||||
{
|
||||
await CleanupOrphanedSnapshotsRules();
|
||||
await CleanupOrphanedRules();
|
||||
}
|
||||
|
||||
private async Task CleanupOrphanedSnapshotsRules()
|
||||
{
|
||||
const string command =
|
||||
@"DELETE snapshots_rules
|
||||
|
|
@ -44,6 +50,16 @@ FROM snapshots_rules
|
|||
WHERE snapshots.WasSuccessful = 0;";
|
||||
await DbContext.Database.ExecuteSqlCommandAsync(command);
|
||||
}
|
||||
|
||||
private async Task CleanupOrphanedRules()
|
||||
{
|
||||
const string command =
|
||||
@"DELETE rules
|
||||
FROM rules
|
||||
LEFT JOIN snapshots_rules ON rules.Id = snapshots_rules.RuleId
|
||||
WHERE snapshots_rules.RuleId IS NULL;";
|
||||
await DbContext.Database.ExecuteSqlCommandAsync(command);
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<FilterListViewUrlDto>> GetListsToCapture(int batchSize) =>
|
||||
await DbContext
|
||||
|
|
|
|||
Loading…
Reference in a new issue