mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-05 21:25:27 +02:00
fix: wire update_checks into telemetry-sync + session count fallback
Three bug fixes: - Telemetry-sync now pings update_checks on successful event sync (previously only in gstack-update-check on cache-miss path) - community-pulse falls back to distinct session_id count when update_checks is empty - Dashboard queries session_id and shows unique session count Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,21 +15,40 @@ Deno.serve(async () => {
|
||||
const weekAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString();
|
||||
const twoWeeksAgo = new Date(Date.now() - 14 * 24 * 60 * 60 * 1000).toISOString();
|
||||
|
||||
// This week's active
|
||||
const { count: thisWeek } = await supabase
|
||||
// This week's active (update_checks)
|
||||
const { count: thisWeekChecks } = await supabase
|
||||
.from("update_checks")
|
||||
.select("*", { count: "exact", head: true })
|
||||
.gte("checked_at", weekAgo);
|
||||
|
||||
// Last week's active (for change %)
|
||||
const { count: lastWeek } = await supabase
|
||||
const { count: lastWeekChecks } = await supabase
|
||||
.from("update_checks")
|
||||
.select("*", { count: "exact", head: true })
|
||||
.gte("checked_at", twoWeeksAgo)
|
||||
.lt("checked_at", weekAgo);
|
||||
|
||||
const current = thisWeek ?? 0;
|
||||
const previous = lastWeek ?? 0;
|
||||
let current = thisWeekChecks ?? 0;
|
||||
let previous = lastWeekChecks ?? 0;
|
||||
|
||||
// Fallback: if update_checks is empty, count distinct sessions from telemetry_events
|
||||
if (current === 0) {
|
||||
const { data: thisWeekSessions } = await supabase
|
||||
.from("telemetry_events")
|
||||
.select("session_id")
|
||||
.eq("event_type", "skill_run")
|
||||
.gte("event_timestamp", weekAgo);
|
||||
|
||||
const { data: lastWeekSessions } = await supabase
|
||||
.from("telemetry_events")
|
||||
.select("session_id")
|
||||
.eq("event_type", "skill_run")
|
||||
.gte("event_timestamp", twoWeeksAgo)
|
||||
.lt("event_timestamp", weekAgo);
|
||||
|
||||
current = new Set((thisWeekSessions ?? []).map((e: { session_id: string }) => e.session_id)).size;
|
||||
previous = new Set((lastWeekSessions ?? []).map((e: { session_id: string }) => e.session_id)).size;
|
||||
}
|
||||
const changePct = previous > 0
|
||||
? Math.round(((current - previous) / previous) * 100)
|
||||
: 0;
|
||||
|
||||
Reference in New Issue
Block a user