-
Notifications
You must be signed in to change notification settings - Fork 499
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 offers table (#5111)
- Loading branch information
Showing
7 changed files
with
179 additions
and
47 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
services/horizon/internal/db2/history/mock_offers_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 MockOffersBatchInsertBuilder struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *MockOffersBatchInsertBuilder) Add(offer Offer) error { | ||
a := m.Called(offer) | ||
return a.Error(0) | ||
} | ||
|
||
func (m *MockOffersBatchInsertBuilder) 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
39 changes: 39 additions & 0 deletions
39
services/horizon/internal/db2/history/offers_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,39 @@ | ||
package history | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/stellar/go/support/db" | ||
) | ||
|
||
// OffersBatchInsertBuilder is used to insert offers into the offers table | ||
type OffersBatchInsertBuilder interface { | ||
Add(offer Offer) error | ||
Exec(ctx context.Context) error | ||
} | ||
|
||
// OffersBatchInsertBuilder is a simple wrapper around db.FastBatchInsertBuilder | ||
type offersBatchInsertBuilder struct { | ||
session db.SessionInterface | ||
builder db.FastBatchInsertBuilder | ||
table string | ||
} | ||
|
||
// NewOffersBatchInsertBuilder constructs a new OffersBatchInsertBuilder instance | ||
func (q *Q) NewOffersBatchInsertBuilder() OffersBatchInsertBuilder { | ||
return &offersBatchInsertBuilder{ | ||
session: q, | ||
builder: db.FastBatchInsertBuilder{}, | ||
table: "offers", | ||
} | ||
} | ||
|
||
// Add adds a new offer to the batch | ||
func (i *offersBatchInsertBuilder) Add(offer Offer) error { | ||
return i.builder.RowStruct(offer) | ||
} | ||
|
||
// Exec writes the batch of offers to the database. | ||
func (i *offersBatchInsertBuilder) 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
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