mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
session: remove variadic State param from ListSessionsByState
We only really ever use it in one place and even then, only for a session State that we no longer use anymore. This is done to make the SQL queries we will need to implement the SQL Store more simple.
This commit is contained in:
parent
66b0f15176
commit
306519fd6d
4 changed files with 17 additions and 24 deletions
|
|
@ -288,8 +288,8 @@ type Store interface {
|
|||
ListSessionsByType(ctx context.Context, t Type) ([]*Session, error)
|
||||
|
||||
// ListSessionsByState returns all sessions currently known to the store
|
||||
// that are in the given states.
|
||||
ListSessionsByState(ctx context.Context, state ...State) ([]*Session,
|
||||
// that are in the given state.
|
||||
ListSessionsByState(ctx context.Context, state State) ([]*Session,
|
||||
error)
|
||||
|
||||
// UpdateSessionRemotePubKey can be used to add the given remote pub key
|
||||
|
|
|
|||
|
|
@ -370,20 +370,14 @@ func (db *BoltStore) ListSessionsByType(_ context.Context, t Type) ([]*Session,
|
|||
}
|
||||
|
||||
// ListSessionsByState returns all sessions currently known to the store that
|
||||
// are in the given states.
|
||||
// are in the given state.
|
||||
//
|
||||
// NOTE: this is part of the Store interface.
|
||||
func (db *BoltStore) ListSessionsByState(_ context.Context, states ...State) (
|
||||
func (db *BoltStore) ListSessionsByState(_ context.Context, state State) (
|
||||
[]*Session, error) {
|
||||
|
||||
return db.listSessions(func(s *Session) bool {
|
||||
for _, state := range states {
|
||||
if s.State == state {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return s.State == state
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -134,17 +134,6 @@ func TestBasicSessionStore(t *testing.T) {
|
|||
assertEqualSessions(t, s2, sessions[0])
|
||||
assertEqualSessions(t, s3, sessions[1])
|
||||
|
||||
sessions, err = db.ListSessionsByState(ctx, StateCreated, StateRevoked)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 3, len(sessions))
|
||||
assertEqualSessions(t, s1, sessions[0])
|
||||
assertEqualSessions(t, s2, sessions[1])
|
||||
assertEqualSessions(t, s3, sessions[2])
|
||||
|
||||
sessions, err = db.ListSessionsByState(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, sessions)
|
||||
|
||||
sessions, err = db.ListSessionsByState(ctx, StateReserved)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, sessions)
|
||||
|
|
|
|||
|
|
@ -102,13 +102,23 @@ func (s *sessionRpcServer) start(ctx context.Context) error {
|
|||
}
|
||||
|
||||
// Start up all previously created sessions.
|
||||
sessions, err := s.cfg.db.ListSessionsByState(
|
||||
ctx, session.StateCreated, session.StateInUse,
|
||||
sessions, err := s.cfg.db.ListSessionsByState(ctx, session.StateCreated)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error listing sessions: %v", err)
|
||||
}
|
||||
|
||||
// For backwards compatibility, we will also resume sessions that are in
|
||||
// the InUse state even though we no longer put sessions into this
|
||||
// state.
|
||||
inUseSessions, err := s.cfg.db.ListSessionsByState(
|
||||
ctx, session.StateInUse,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error listing sessions: %v", err)
|
||||
}
|
||||
|
||||
sessions = append(sessions, inUseSessions...)
|
||||
|
||||
for _, sess := range sessions {
|
||||
key := sess.LocalPublicKey.SerializeCompressed()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue