Skip to content

Commit 2b9b927

Browse files
committed
Use the thumbnail that is as close to the thumbnail time
1 parent 441c4b3 commit 2b9b927

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/auth/recordingmetadata/recordingmetadatav1/recordingmetadata.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"context"
2424
"io"
2525
"log/slog"
26+
"math"
2627
"math/rand/v2"
2728
"sync"
2829
"time"
@@ -169,9 +170,17 @@ func (s *RecordingMetadataService) ProcessSessionRecording(ctx context.Context,
169170
"session_id", sessionID, "error", err)
170171
}
171172

172-
if startOffset < thumbnailTime {
173-
// keep updating the recording thumbnail until we reach the ideal thumbnail time (in case there are
174-
// periods of inactivity and no thumbnails are captured for a while)
173+
if recordingThumbnail == nil {
174+
recordingThumbnail = thumbnail
175+
176+
return
177+
}
178+
179+
previousDiff := math.Abs(float64(thumbnailTime - recordingThumbnail.StartOffset.AsDuration()))
180+
diff := math.Abs(float64(thumbnailTime - startOffset))
181+
182+
if diff < previousDiff {
183+
// this thumbnail is closer to the ideal thumbnail time, use it instead
175184
recordingThumbnail = thumbnail
176185
}
177186
}

0 commit comments

Comments
 (0)