feat(sleep): add HasAnyCompletedSession for feature discovery

Add HasAnyCompletedSession() method to sleep storage to check if any
sleep sessions have been completed. This is used by the feature discovery
notification system to determine when to fire the "first sleep session
complete" notification.

A completed session has both sleep_onset and wake_time set.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
jedarden 2026-05-04 04:07:27 -04:00
parent a50a4f7949
commit 1845c09bb1

View file

@ -539,3 +539,17 @@ func (s *Storage) DeleteOldSessions(days int) (int64, error) {
return result.RowsAffected()
}
// HasAnyCompletedSession returns true if at least one sleep session has been completed.
// A completed session has both sleep_onset and wake_time set.
func (s *Storage) HasAnyCompletedSession() bool {
s.mu.RLock()
defer s.mu.RUnlock()
var count int
err := s.db.QueryRow(`
SELECT COUNT(*) FROM sleep_sessions
WHERE sleep_onset > 0 AND wake_time > 0
`).Scan(&count)
return err == nil && count > 0
}