mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
parent
a70a3673bf
commit
7bd7885b09
3 changed files with 8 additions and 7 deletions
|
|
@ -19,7 +19,8 @@ public ListDetailsDtoMappingProfile() =>
|
|||
l.Snapshots.Where(s => s.WasSuccessful)
|
||||
.OrderByDescending(s => s.CreatedDateUtc)
|
||||
.FirstOrDefault()
|
||||
.SnapshotRules.Count))
|
||||
.SnapshotRules
|
||||
.Count))
|
||||
.ForMember(d => d.UpdatedDate,
|
||||
c => c.MapFrom(l =>
|
||||
l.Snapshots.Where(s => s.WasSuccessful)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class Snapshot
|
|||
{
|
||||
private const int BatchSize = 500;
|
||||
private readonly FilterListsDbContext dbContext;
|
||||
private readonly FilterListViewUrlDto list;
|
||||
private readonly string listViewUrl;
|
||||
private readonly Data.Entities.Snapshot snapEntity;
|
||||
private readonly TelemetryClient telemetryClient;
|
||||
private readonly string uaString;
|
||||
|
|
@ -27,8 +27,8 @@ public class Snapshot
|
|||
public Snapshot(FilterListsDbContext dbContext, FilterListViewUrlDto list, string uaString)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
this.list = list;
|
||||
this.uaString = uaString;
|
||||
listViewUrl = list.ViewUrl;
|
||||
snapEntity = new Data.Entities.Snapshot
|
||||
{
|
||||
FilterListId = list.Id
|
||||
|
|
@ -39,7 +39,7 @@ public Snapshot(FilterListsDbContext dbContext, FilterListViewUrlDto list, strin
|
|||
public async Task TrySaveAsync()
|
||||
{
|
||||
await AddSnapEntity();
|
||||
if (!list.ViewUrl.IsValidHttpOrHttpsUrl())
|
||||
if (!listViewUrl.IsValidHttpOrHttpsUrl())
|
||||
return;
|
||||
try
|
||||
{
|
||||
|
|
@ -91,7 +91,7 @@ private async Task GetLines()
|
|||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(uaString);
|
||||
var response = await httpClient.GetAsync(list.ViewUrl, HttpCompletionOption.ResponseHeadersRead);
|
||||
var response = await httpClient.GetAsync(listViewUrl, HttpCompletionOption.ResponseHeadersRead);
|
||||
snapEntity.HttpStatusCode = (uint)response.StatusCode;
|
||||
response.EnsureSuccessStatusCode();
|
||||
lines = new HashSet<string>();
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@ public SnapshotBatch(FilterListsDbContext dbContext, IEnumerable<string> lines,
|
|||
public async Task SaveAsync()
|
||||
{
|
||||
var existingRules = dbContext.Rules.Join(lines, rule => rule.Raw, line => line, (rule, line) => rule);
|
||||
var newRules = lines.Except(existingRules.Select(r => r.Raw)).Select(l => new Rule { Raw = l }).ToList();
|
||||
var newRules = lines.Except(existingRules.Select(r => r.Raw)).Select(l => new Rule {Raw = l}).ToList();
|
||||
dbContext.Rules.AddRange(newRules);
|
||||
var rules = existingRules.Concat(newRules);
|
||||
var snapshotRules = rules.Select(r => new SnapshotRule { Rule = r });
|
||||
var snapshotRules = rules.Select(r => new SnapshotRule {Rule = r});
|
||||
snapEntity.SnapshotRules = snapshotRules.ToList();
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue