MCPcopy Index your code
hub / github.com/docker/docker-agent / GetSessions

Method GetSessions

pkg/session/store.go:819–850  ·  view source on GitHub ↗

GetSessions retrieves all root sessions (excludes sub-sessions)

(ctx context.Context)

Source from the content-addressed store, hash-verified

817
818// GetSessions retrieves all root sessions (excludes sub-sessions)
819func (s *SQLiteSessionStore) GetSessions(ctx context.Context) ([]*Session, error) {
820 rows, err := s.db.QueryContext(ctx,
821 "SELECT "+sessionSelectColumns+" FROM sessions WHERE parent_id IS NULL OR parent_id = '' ORDER BY created_at DESC")
822 if err != nil {
823 return nil, err
824 }
825 defer rows.Close()
826
827 // Collect sessions first to close the rows before loading items
828 var sessions []*Session
829 for rows.Next() {
830 session, err := scanSession(rows)
831 if err != nil {
832 return nil, err
833 }
834 sessions = append(sessions, session)
835 }
836 if err := rows.Err(); err != nil {
837 return nil, err
838 }
839
840 // Load messages for each session
841 for _, session := range sessions {
842 items, err := s.loadSessionItems(ctx, s.db, session.ID)
843 if err != nil {
844 return nil, fmt.Errorf("loading items for session %s: %w", session.ID, err)
845 }
846 session.Messages = items
847 }
848
849 return sessions, nil
850}
851
852// GetSessionSummaries retrieves lightweight session metadata for listing (excludes sub-sessions).
853// This is much faster than GetSessions as it doesn't load message content.

Callers 4

TestGetSessionsFunction · 0.95
TestSaveRunSessionsFunction · 0.95

Calls 6

loadSessionItemsMethod · 0.95
scanSessionFunction · 0.85
QueryContextMethod · 0.80
CloseMethod · 0.65
NextMethod · 0.65
ErrMethod · 0.65

Tested by 4

TestGetSessionsFunction · 0.76
TestSaveRunSessionsFunction · 0.76