-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
services/horizon: Use COPY for inserting into liquidity_pools table (#…
- Loading branch information
Showing
7 changed files
with
164 additions
and
35 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
services/horizon/internal/db2/history/liquidity_pool_batch_insert_builder.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package history | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/stellar/go/support/db" | ||
) | ||
|
||
type LiquidityPoolBatchInsertBuilder interface { | ||
Add(liquidityPool LiquidityPool) error | ||
Exec(ctx context.Context) error | ||
} | ||
|
||
type liquidityPoolBatchInsertBuilder struct { | ||
session db.SessionInterface | ||
builder db.FastBatchInsertBuilder | ||
table string | ||
} | ||
|
||
func (q *Q) NewLiquidityPoolBatchInsertBuilder() LiquidityPoolBatchInsertBuilder { | ||
return &liquidityPoolBatchInsertBuilder{ | ||
session: q, | ||
builder: db.FastBatchInsertBuilder{}, | ||
table: "liquidity_pools", | ||
} | ||
} | ||
|
||
// Add adds a new liquidity pool to the batch | ||
func (i *liquidityPoolBatchInsertBuilder) Add(liquidityPool LiquidityPool) error { | ||
return i.builder.RowStruct(liquidityPool) | ||
} | ||
|
||
// Exec writes the batch of liquidity pools to the database. | ||
func (i *liquidityPoolBatchInsertBuilder) Exec(ctx context.Context) error { | ||
return i.builder.Exec(ctx, i.session, i.table) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
services/horizon/internal/db2/history/mock_liquidity_pool_batch_insert_builder.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package history | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type MockLiquidityPoolBatchInsertBuilder struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *MockLiquidityPoolBatchInsertBuilder) Add(liquidityPool LiquidityPool) error { | ||
a := m.Called(liquidityPool) | ||
return a.Error(0) | ||
} | ||
|
||
func (m *MockLiquidityPoolBatchInsertBuilder) Exec(ctx context.Context) error { | ||
a := m.Called(ctx) | ||
return a.Error(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters