Skip to content

Commit

Permalink
Fix invalidation query
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro committed Aug 28, 2024
1 parent 016df4c commit f1af191
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/Services/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,20 +326,21 @@ protected function invalidateObsoleteTags(): void

$maxUrls = EdgeFlush::cdn()->maxUrls();

$query = "
from edge_flush_urls
where edge_flush_urls.was_purged_at is null
and edge_flush_urls.obsolete = true
and edge_flush_urls.is_valid = true
order by edge_flush_urls.hits desc
";

/**
* Get a count
*/
$total = DB::select("
select count(distinct edge_flush_urls.id, edge_flush_urls.hits, edge_flush_urls.url, edge_flush_urls.url_hash) as total
{$query}
select count(*) as total
from (
select distinct edge_flush_urls.id,
edge_flush_urls.hits,
edge_flush_urls.url,
edge_flush_urls.url_hash
from edge_flush_urls
where edge_flush_urls.was_purged_at is null
and edge_flush_urls.obsolete = true
and edge_flush_urls.is_valid = true
) as distinct_values;
");

$total = blank($total[0] ?? null) ? 0 : $total[0]->total;
Expand All @@ -355,7 +356,11 @@ protected function invalidateObsoleteTags(): void
$rows = Helpers::collect(
DB::select("
select distinct edge_flush_urls.id, edge_flush_urls.hits, edge_flush_urls.url, edge_flush_urls.url_hash
{$query}
from edge_flush_urls
where edge_flush_urls.was_purged_at is null
and edge_flush_urls.obsolete = true
and edge_flush_urls.is_valid = true
order by edge_flush_urls.hits desc
limit {$maxUrls}
"),
)->map(fn($row) => new Url((array) $row));
Expand Down

0 comments on commit f1af191

Please sign in to comment.