Make the small refresh faster (probably better planner hinting?)

Courtesy by @zoldar

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
This commit is contained in:
Adam Rutkowski 2025-09-25 09:37:33 +02:00
parent b7946f41f4
commit 03d18bc4ff
1 changed files with 3 additions and 4 deletions

View File

@ -41,18 +41,17 @@ defmodule Plausible.ConsolidatedView.Cache do
@spec refresh_updated_recently(Keyword.t()) :: :ok
def refresh_updated_recently(opts) do
recently_updated_site_ids =
recently_updated_views =
from sc in ConsolidatedView.sites(),
join: sr in ^Plausible.Site.regular(),
on: sc.team_id == sr.team_id,
where: sr.updated_at > ago(^15, "minute") or sc.updated_at > ago(^15, "minute"),
select: sc.id
select: sc
query =
from sc in ConsolidatedView.sites(),
from sc in subquery(recently_updated_views),
join: sr in ^Plausible.Site.regular(),
on: sr.team_id == sc.team_id,
where: sc.id in subquery(recently_updated_site_ids),
group_by: [sc.domain, sc.updated_at],
order_by: [desc: sc.updated_at],
select: %{consolidated_view_id: sc.domain, site_ids: fragment("array_agg(?)", sr.id)}