mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
update algo for getting lists to scrape
This commit is contained in:
parent
f651a33ad8
commit
fcfdd2c0ac
1 changed files with 26 additions and 2 deletions
|
|
@ -28,8 +28,32 @@ public async Task ScrapeAsync(int batchSize)
|
|||
|
||||
private async Task<List<FilterListViewUrlDto>> GetNextListsToScrape(int batchSize)
|
||||
{
|
||||
//TODO: order by least recently scraped
|
||||
return await dbContext.FilterLists.Take(batchSize).ProjectTo<FilterListViewUrlDto>().ToListAsync();
|
||||
var neverScraped = await GetNeverScrapedLists(batchSize);
|
||||
if (neverScraped.Count == batchSize)
|
||||
return neverScraped;
|
||||
var leastRecentlyScraped = await GetLeastRecentlyScrapedLists(batchSize - neverScraped.Count);
|
||||
return neverScraped.Concat(leastRecentlyScraped).ToList();
|
||||
}
|
||||
|
||||
private async Task<List<FilterListViewUrlDto>> GetNeverScrapedLists(int batchSize)
|
||||
{
|
||||
return await dbContext.FilterLists
|
||||
.Where(x => x.Scrapes.Count == 0)
|
||||
.Take(batchSize)
|
||||
.ProjectTo<FilterListViewUrlDto>()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
private async Task<List<FilterListViewUrlDto>> GetLeastRecentlyScrapedLists(int batchSize)
|
||||
{
|
||||
return await dbContext.Scrapes
|
||||
.GroupBy(x => x.FilterList)
|
||||
.Select(x => x.OrderByDescending(y => y.CreatedDateUtc).First())
|
||||
.OrderBy(x => x.CreatedDateUtc)
|
||||
.Select(x => x.FilterList)
|
||||
.Take(batchSize)
|
||||
.ProjectTo<FilterListViewUrlDto>()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<Snapshot>> GetSnapshots(IEnumerable<FilterListViewUrlDto> lists)
|
||||
|
|
|
|||
Loading…
Reference in a new issue