fix: active sessions query, chart update performance
- Active sessions query now finds truly active sessions (started anytime, no session.end ever) instead of only today's sessions - Use uPlot setData() for live WS updates instead of destroying and recreating the chart on every event - Destroy chart only on window change so it recreates with new scale Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -36,23 +36,21 @@ func (d *DB) GetSummary(ctx context.Context) (*Summary, error) {
|
||||
now := time.Now()
|
||||
midnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
|
||||
// Active sessions: sessions that started today but have not ended today
|
||||
// Active sessions: sessions with a session.start but no session.end (ever)
|
||||
activeQ := `
|
||||
SELECT COUNT(DISTINCT session_id)
|
||||
FROM events
|
||||
WHERE type = 'session.start'
|
||||
AND ts >= $1
|
||||
AND session_id IS NOT NULL
|
||||
AND session_id NOT IN (
|
||||
SELECT DISTINCT session_id
|
||||
FROM events
|
||||
WHERE type = 'session.end'
|
||||
AND ts >= $1
|
||||
AND session_id IS NOT NULL
|
||||
)
|
||||
`
|
||||
var activeSessions int
|
||||
if err := d.sql.QueryRowContext(ctx, activeQ, midnight).Scan(&activeSessions); err != nil {
|
||||
if err := d.sql.QueryRowContext(ctx, activeQ).Scan(&activeSessions); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user