func()

in sessions/sessions.go [121:170]


func (s *collection) Update() error {
	s.Lock()
	defer s.Unlock()
	localSessions, err := fetchSessions(s.localBackend)
	if err != nil {
		return fmt.Errorf("failure listing the local sessions: %w", err)
	}
	remoteSessions, err := fetchSessions(s.remoteBackend)
	if err != nil {
		// We don't treat failures communicating with the remote backend as terminal,
		// and instead simply treat the sessions hosted there as being lost. If the
		// remote backend becomes available again we will rediscover the remote sessions
		// at that point.
		log.Printf("failure listing the remote sessions: %v", err)
		remoteSessions = nil
	}
	updatedSessions := make(map[string]*sessionRecord)
	for _, session := range localSessions {
		if session.ID == "" {
			// Ignore incomplete sessions from the backend
			continue
		}
		unifiedID, ok := s.sessionUnifiedIDs[session.ID]
		if !ok {
			unifiedID = session.ID
			s.sessionUnifiedIDs[session.ID] = unifiedID
		}
		updatedSessions[unifiedID] = &sessionRecord{
			backend:     s.localBackend,
			backendView: session,
		}
	}
	for _, session := range remoteSessions {
		if session.ID == "" {
			// Ignore incomplete sessions from the backend
			continue
		}
		unifiedID, ok := s.sessionUnifiedIDs[session.ID]
		if !ok {
			unifiedID = session.ID
			s.sessionUnifiedIDs[session.ID] = unifiedID
		}
		updatedSessions[unifiedID] = &sessionRecord{
			backend:     s.remoteBackend,
			backendView: session,
		}
	}
	s.sessionsMap = updatedSessions
	return nil
}