mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
loopdb: add batch insert
This commit adds a batch insert to the interface. This greatly reduces the time the migration will take. It is not implemented for the boltdb, as we will not be supporting migrating to the boltdb.
This commit is contained in:
parent
becc8a38d8
commit
5d9d7c5c6e
3 changed files with 57 additions and 0 deletions
|
|
@ -20,6 +20,10 @@ type SwapStore interface {
|
||||||
CreateLoopOut(ctx context.Context, hash lntypes.Hash,
|
CreateLoopOut(ctx context.Context, hash lntypes.Hash,
|
||||||
swap *LoopOutContract) error
|
swap *LoopOutContract) error
|
||||||
|
|
||||||
|
// BatchCreateLoopOut creates a batch of loop out swaps to the store.
|
||||||
|
BatchCreateLoopOut(ctx context.Context,
|
||||||
|
swaps map[lntypes.Hash]*LoopOutContract) error
|
||||||
|
|
||||||
// UpdateLoopOut stores a new event for a target loop out swap. This
|
// UpdateLoopOut stores a new event for a target loop out swap. This
|
||||||
// appends to the event log for a particular swap as it goes through
|
// appends to the event log for a particular swap as it goes through
|
||||||
// the various stages in its lifetime.
|
// the various stages in its lifetime.
|
||||||
|
|
@ -33,12 +37,20 @@ type SwapStore interface {
|
||||||
CreateLoopIn(ctx context.Context, hash lntypes.Hash,
|
CreateLoopIn(ctx context.Context, hash lntypes.Hash,
|
||||||
swap *LoopInContract) error
|
swap *LoopInContract) error
|
||||||
|
|
||||||
|
// BatchCreateLoopIn creates a batch of loop in swaps to the store.
|
||||||
|
BatchCreateLoopIn(ctx context.Context,
|
||||||
|
swaps map[lntypes.Hash]*LoopInContract) error
|
||||||
|
|
||||||
// UpdateLoopIn stores a new event for a target loop in swap. This
|
// UpdateLoopIn stores a new event for a target loop in swap. This
|
||||||
// appends to the event log for a particular swap as it goes through
|
// appends to the event log for a particular swap as it goes through
|
||||||
// the various stages in its lifetime.
|
// the various stages in its lifetime.
|
||||||
UpdateLoopIn(ctx context.Context, hash lntypes.Hash, time time.Time,
|
UpdateLoopIn(ctx context.Context, hash lntypes.Hash, time time.Time,
|
||||||
state SwapStateData) error
|
state SwapStateData) error
|
||||||
|
|
||||||
|
// BatchInsertUpdate inserts batch of swap updates to the store.
|
||||||
|
BatchInsertUpdate(ctx context.Context,
|
||||||
|
updateData map[lntypes.Hash][]BatchInsertUpdateData) error
|
||||||
|
|
||||||
// PutLiquidityParams writes the serialized `manager.Parameters` bytes
|
// PutLiquidityParams writes the serialized `manager.Parameters` bytes
|
||||||
// into the bucket.
|
// into the bucket.
|
||||||
//
|
//
|
||||||
|
|
@ -57,4 +69,11 @@ type SwapStore interface {
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BatchInsertUpdateData is a struct that holds the data for the
|
||||||
|
// BatchInsertUpdate function.
|
||||||
|
type BatchInsertUpdateData struct {
|
||||||
|
Time time.Time
|
||||||
|
State SwapStateData
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(roasbeef): back up method in interface?
|
// TODO(roasbeef): back up method in interface?
|
||||||
|
|
|
||||||
|
|
@ -985,3 +985,24 @@ func (s *boltSwapStore) fetchLoopInSwap(rootBucket *bbolt.Bucket,
|
||||||
|
|
||||||
return &loop, nil
|
return &loop, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BatchCreateLoopOut creates a batch of swaps to the store.
|
||||||
|
func (b *boltSwapStore) BatchCreateLoopOut(ctx context.Context,
|
||||||
|
swaps map[lntypes.Hash]*LoopOutContract) error {
|
||||||
|
|
||||||
|
return errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
// BatchCreateLoopIn creates a batch of loop in swaps to the store.
|
||||||
|
func (b *boltSwapStore) BatchCreateLoopIn(ctx context.Context,
|
||||||
|
swaps map[lntypes.Hash]*LoopInContract) error {
|
||||||
|
|
||||||
|
return errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
// BatchInsertUpdate inserts batch of swap updates to the store.
|
||||||
|
func (b *boltSwapStore) BatchInsertUpdate(ctx context.Context,
|
||||||
|
updateData map[lntypes.Hash][]BatchInsertUpdateData) error {
|
||||||
|
|
||||||
|
return errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -303,3 +303,20 @@ func (s *storeMock) assertStoreFinished(expectedResult loopdb.SwapState) {
|
||||||
s.t.Fatalf("expected swap to be finished")
|
s.t.Fatalf("expected swap to be finished")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func (b *storeMock) BatchCreateLoopOut(ctx context.Context,
|
||||||
|
swaps map[lntypes.Hash]*loopdb.LoopOutContract) error {
|
||||||
|
|
||||||
|
return errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *storeMock) BatchCreateLoopIn(ctx context.Context,
|
||||||
|
swaps map[lntypes.Hash]*loopdb.LoopInContract) error {
|
||||||
|
|
||||||
|
return errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *storeMock) BatchInsertUpdate(ctx context.Context,
|
||||||
|
updateData map[lntypes.Hash][]loopdb.BatchInsertUpdateData) error {
|
||||||
|
|
||||||
|
return errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue