feat(ender): handle the negative duration sessions

This commit is contained in:
Alexander 2025-03-24 10:02:42 +01:00
parent e6eb41536d
commit e04c2aa251

View file

@ -121,7 +121,16 @@ func (s *storageImpl) Get(sessionID uint64) (*Session, error) {
// For the ender service only // For the ender service only
func (s *storageImpl) GetMany(sessionIDs []uint64) ([]*Session, error) { func (s *storageImpl) GetMany(sessionIDs []uint64) ([]*Session, error) {
rows, err := s.db.Query("SELECT session_id, COALESCE( duration, 0 ), start_ts FROM sessions WHERE session_id = ANY($1)", pq.Array(sessionIDs)) rows, err := s.db.Query(`
SELECT
session_id,
CASE
WHEN duration IS NULL OR duration < 0 THEN 0
ELSE duration
END,
start_ts
FROM sessions
WHERE session_id = ANY($1)`, pq.Array(sessionIDs))
if err != nil { if err != nil {
return nil, err return nil, err
} }