forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into fast_copy_ledger_…
…range
- Loading branch information
Showing
20 changed files
with
494 additions
and
234 deletions.
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
services/horizon/internal/db2/history/account_data_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,50 @@ | ||
package history | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/stellar/go/support/db" | ||
) | ||
|
||
type AccountDataBatchInsertBuilder interface { | ||
Add(data Data) error | ||
Exec(ctx context.Context) error | ||
} | ||
|
||
type accountDataBatchInsertBuilder struct { | ||
session db.SessionInterface | ||
builder db.FastBatchInsertBuilder | ||
table string | ||
} | ||
|
||
func (q *Q) NewAccountDataBatchInsertBuilder() AccountDataBatchInsertBuilder { | ||
return &accountDataBatchInsertBuilder{ | ||
session: q, | ||
builder: db.FastBatchInsertBuilder{}, | ||
table: "accounts_data", | ||
} | ||
} | ||
|
||
// Add adds a new account data to the batch | ||
func (i *accountDataBatchInsertBuilder) Add(data Data) error { | ||
ledgerKey, err := accountDataKeyToString(AccountDataKey{ | ||
AccountID: data.AccountID, | ||
DataName: data.Name, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
return i.builder.Row(map[string]interface{}{ | ||
"ledger_key": ledgerKey, | ||
"account_id": data.AccountID, | ||
"name": data.Name, | ||
"value": data.Value, | ||
"last_modified_ledger": data.LastModifiedLedger, | ||
"sponsor": data.Sponsor, | ||
}) | ||
} | ||
|
||
// Exec writes the batch of account data to the database. | ||
func (i *accountDataBatchInsertBuilder) 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
39 changes: 39 additions & 0 deletions
39
services/horizon/internal/db2/history/accounts_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" | ||
) | ||
|
||
// AccountsBatchInsertBuilder is used to insert accounts into the accounts table | ||
type AccountsBatchInsertBuilder interface { | ||
Add(account AccountEntry) error | ||
Exec(ctx context.Context) error | ||
} | ||
|
||
// AccountsBatchInsertBuilder is a simple wrapper around db.FastBatchInsertBuilder | ||
type accountsBatchInsertBuilder struct { | ||
session db.SessionInterface | ||
builder db.FastBatchInsertBuilder | ||
table string | ||
} | ||
|
||
// NewAccountsBatchInsertBuilder constructs a new AccountsBatchInsertBuilder instance | ||
func (q *Q) NewAccountsBatchInsertBuilder() AccountsBatchInsertBuilder { | ||
return &accountsBatchInsertBuilder{ | ||
session: q, | ||
builder: db.FastBatchInsertBuilder{}, | ||
table: "accounts", | ||
} | ||
} | ||
|
||
// Add adds a new account to the batch | ||
func (i *accountsBatchInsertBuilder) Add(account AccountEntry) error { | ||
return i.builder.RowStruct(account) | ||
} | ||
|
||
// Exec writes the batch of accounts to the database. | ||
func (i *accountsBatchInsertBuilder) 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_account_data_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 MockAccountDataBatchInsertBuilder struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *MockAccountDataBatchInsertBuilder) Add(data Data) error { | ||
a := m.Called(data) | ||
return a.Error(0) | ||
} | ||
|
||
func (m *MockAccountDataBatchInsertBuilder) Exec(ctx context.Context) error { | ||
a := m.Called(ctx) | ||
return a.Error(0) | ||
} |
21 changes: 21 additions & 0 deletions
21
services/horizon/internal/db2/history/mock_accounts_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 MockAccountsBatchInsertBuilder struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *MockAccountsBatchInsertBuilder) Add(account AccountEntry) error { | ||
a := m.Called(account) | ||
return a.Error(0) | ||
} | ||
|
||
func (m *MockAccountsBatchInsertBuilder) 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
21 changes: 21 additions & 0 deletions
21
services/horizon/internal/db2/history/mock_trust_lines_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 MockTrustLinesBatchInsertBuilder struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *MockTrustLinesBatchInsertBuilder) Add(line TrustLine) error { | ||
a := m.Called(line) | ||
return a.Error(0) | ||
} | ||
|
||
func (m *MockTrustLinesBatchInsertBuilder) Exec(ctx context.Context) error { | ||
a := m.Called(ctx) | ||
return a.Error(0) | ||
} |
39 changes: 39 additions & 0 deletions
39
services/horizon/internal/db2/history/trust_lines_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" | ||
) | ||
|
||
// TrustLinesBatchInsertBuilder is used to insert trustlines into the trust_lines table | ||
type TrustLinesBatchInsertBuilder interface { | ||
Add(line TrustLine) error | ||
Exec(ctx context.Context) error | ||
} | ||
|
||
// trustLinesBatchInsertBuilder is a simple wrapper around db.FastBatchInsertBuilder | ||
type trustLinesBatchInsertBuilder struct { | ||
session db.SessionInterface | ||
builder db.FastBatchInsertBuilder | ||
table string | ||
} | ||
|
||
// NewTrustLinesBatchInsertBuilder constructs a new TrustLinesBatchInsertBuilder instance | ||
func (q *Q) NewTrustLinesBatchInsertBuilder() TrustLinesBatchInsertBuilder { | ||
return &trustLinesBatchInsertBuilder{ | ||
session: q, | ||
builder: db.FastBatchInsertBuilder{}, | ||
table: "trust_lines", | ||
} | ||
} | ||
|
||
// Add adds a new trustline to the batch | ||
func (i *trustLinesBatchInsertBuilder) Add(line TrustLine) error { | ||
return i.builder.RowStruct(line) | ||
} | ||
|
||
// Exec writes the batch of trust lines to the database. | ||
func (i *trustLinesBatchInsertBuilder) 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
Oops, something went wrong.