From 89949fdfd6ea7152ac6f07fe8d7df9f0c7a1c2b7 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Wed, 4 Mar 2026 15:18:03 -0600 Subject: [PATCH] fix: deduplicate Preseem sync entries in activity feed Group sync entries by minute to show only one entry per minute instead of multiple duplicate entries with the same timestamp. This aggregates: - Total records synced in that minute - Average sync duration - Most recent status This keeps the activity feed informative while reducing noise from rapid syncs happening within the same minute. --- lib/towerops/activity_feed.ex | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/towerops/activity_feed.ex b/lib/towerops/activity_feed.ex index 5b8c5519..5734104b 100644 --- a/lib/towerops/activity_feed.ex +++ b/lib/towerops/activity_feed.ex @@ -296,19 +296,19 @@ defmodule Towerops.ActivityFeed do # --- Preseem Syncs --- defp fetch_source(:sync, org_id, after_dt, before_dt, limit) do + # Group by minute to show only one sync entry per minute (deduplicate rapid syncs) query = from(sl in SyncLog, where: sl.organization_id == ^org_id, - # Only show failed syncs in activity feed, not successful ones - where: sl.status != "success", select: %{ - id: sl.id, - timestamp: sl.inserted_at, - status: sl.status, - records_synced: sl.records_synced, - duration_ms: sl.duration_ms + id: max(sl.id), + timestamp: fragment("date_trunc('minute', ?)", sl.inserted_at), + status: fragment("array_agg(? ORDER BY ? DESC)[1]", sl.status, sl.inserted_at), + records_synced: sum(sl.records_synced), + duration_ms: avg(sl.duration_ms) }, - order_by: [desc: sl.inserted_at], + group_by: fragment("date_trunc('minute', ?)", sl.inserted_at), + order_by: [desc: fragment("date_trunc('minute', ?)", sl.inserted_at)], limit: ^limit )