mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
firewalldb: thread contexts to FetchAllPairs
Update the FetchAllPairs method of the PrivacyMapTx interface to take a context.
This commit is contained in:
parent
5b31f16446
commit
ef93611489
4 changed files with 12 additions and 10 deletions
|
|
@ -1151,8 +1151,8 @@ func (m *mockPrivacyMapDB) RealToPseudo(_ context.Context, real string) (string,
|
|||
return p, nil
|
||||
}
|
||||
|
||||
func (m *mockPrivacyMapDB) FetchAllPairs() (*firewalldb.PrivacyMapPairs,
|
||||
error) {
|
||||
func (m *mockPrivacyMapDB) FetchAllPairs(_ context.Context) (
|
||||
*firewalldb.PrivacyMapPairs, error) {
|
||||
|
||||
return firewalldb.NewPrivacyMapPairs(m.r2p), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ type PrivacyMapTx interface {
|
|||
|
||||
// FetchAllPairs loads and returns the real-to-pseudo pairs in the form
|
||||
// of a PrivacyMapPairs struct.
|
||||
FetchAllPairs() (*PrivacyMapPairs, error)
|
||||
FetchAllPairs(ctx context.Context) (*PrivacyMapPairs, error)
|
||||
}
|
||||
|
||||
// privacyMapDB is an implementation of PrivacyMapDB.
|
||||
|
|
@ -287,7 +287,9 @@ func (p *privacyMapTx) RealToPseudo(_ context.Context, real string) (string,
|
|||
// FetchAllPairs loads and returns the real-to-pseudo pairs.
|
||||
//
|
||||
// NOTE: this is part of the PrivacyMapTx interface.
|
||||
func (p *privacyMapTx) FetchAllPairs() (*PrivacyMapPairs, error) {
|
||||
func (p *privacyMapTx) FetchAllPairs(_ context.Context) (*PrivacyMapPairs,
|
||||
error) {
|
||||
|
||||
privacyBucket, err := getBucket(p.boltTx, privacyBucketKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ func TestPrivacyMapStorage(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, "real", real)
|
||||
|
||||
pairs, err := tx.FetchAllPairs()
|
||||
pairs, err := tx.FetchAllPairs(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.EqualValues(t, pairs.pairs, map[string]string{
|
||||
|
|
@ -70,7 +70,7 @@ func TestPrivacyMapStorage(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, "real 2", real)
|
||||
|
||||
pairs, err := tx.FetchAllPairs()
|
||||
pairs, err := tx.FetchAllPairs(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.EqualValues(t, pairs.pairs, map[string]string{
|
||||
|
|
@ -85,7 +85,7 @@ func TestPrivacyMapStorage(t *testing.T) {
|
|||
_ = pdb3.Update(ctx, func(ctx context.Context, tx PrivacyMapTx) error {
|
||||
// Check that calling FetchAllPairs returns an empty map if
|
||||
// nothing exists in the DB yet.
|
||||
m, err := tx.FetchAllPairs()
|
||||
m, err := tx.FetchAllPairs(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, m.pairs)
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ func TestPrivacyMapStorage(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Check that FetchAllPairs correctly returns all the pairs.
|
||||
pairs, err := tx.FetchAllPairs()
|
||||
pairs, err := tx.FetchAllPairs(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.EqualValues(t, pairs.pairs, map[string]string{
|
||||
|
|
|
|||
|
|
@ -901,10 +901,10 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
|
|||
linkedGroupSession = groupSess
|
||||
|
||||
privDB := s.cfg.privMap(groupID)
|
||||
err = privDB.View(ctx, func(_ context.Context,
|
||||
err = privDB.View(ctx, func(ctx context.Context,
|
||||
tx firewalldb.PrivacyMapTx) error {
|
||||
|
||||
knownPrivMapPairs, err = tx.FetchAllPairs()
|
||||
knownPrivMapPairs, err = tx.FetchAllPairs(ctx)
|
||||
|
||||
return err
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue