From 5365eef8ac3ca2ee010a675c20c3df552888444f Mon Sep 17 00:00:00 2001 From: Gal Dayan Date: Thu, 12 Mar 2026 13:26:58 +0200 Subject: [PATCH] fix: bucket analytics by lastActivityAt instead of startedAt (#58) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sessions are now attributed to the time they were last active, not when they were created. This fixes the timeline showing spikes at the wrong hours — e.g. a session started at 05:00 but active until 12:00 now appears in the 12:00 bucket instead of 05:00. Also updates date range filtering to use lastActivityAt so sessions active within the window are included even if started before it. --- backend/src/routes.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/src/routes.ts b/backend/src/routes.ts index 73fb068..cf41913 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -805,9 +805,10 @@ router.get("/analytics", async (req: Request, res: Response) => { effectiveFrom = threeDaysAgo.toISOString(); } - // Filter by date range using startedAt - if (effectiveFrom) sessions = sessions.filter((s) => s.startedAt >= effectiveFrom!); - if (to) sessions = sessions.filter((s) => s.startedAt <= to); + // Filter by date range using lastActivityAt so sessions active in the + // window are included even if they started before it (#58) + if (effectiveFrom) sessions = sessions.filter((s) => (s.lastActivityAt || s.startedAt) >= effectiveFrom!); + if (to) sessions = sessions.filter((s) => (s.lastActivityAt || s.startedAt) <= to); // Get project tags for all sessions const sessionIds = sessions.map((s) => s.id);