Skip to content

Commit

Permalink
rename bulkInsert function
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirms committed Aug 12, 2024
1 parent 3a60216 commit 877cfb4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions services/horizon/internal/db2/history/account_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ func (a *AccountLoader) Exec(ctx context.Context, session db.SessionInterface) e
sort.Strings(addresses)

var accounts []Account
err := bulkInsert(
err := bulkGetOrCreate(
ctx,
q,
"history_accounts",
[]bulkInsertField{
[]columnValues{
{
name: "address",
dbType: "character varying(64)",
Expand Down Expand Up @@ -139,13 +139,13 @@ func (a *AccountLoader) Name() string {
return "AccountLoader"
}

type bulkInsertField struct {
type columnValues struct {
name string
dbType string
objects []string
}

func bulkInsert(ctx context.Context, q *Q, table string, fields []bulkInsertField, response interface{}) error {
func bulkGetOrCreate(ctx context.Context, q *Q, table string, fields []columnValues, response interface{}) error {
unnestPart := make([]string, 0, len(fields))
insertFieldsPart := make([]string, 0, len(fields))
pqArrays := make([]interface{}, 0, len(fields))
Expand Down
4 changes: 2 additions & 2 deletions services/horizon/internal/db2/history/asset_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ func (a *AssetLoader) Exec(ctx context.Context, session db.SessionInterface) err
}

var rows []Asset
err := bulkInsert(
err := bulkGetOrCreate(
ctx,
q,
"history_assets",
[]bulkInsertField{
[]columnValues{
{
name: "asset_code",
dbType: "character varying(12)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ func (a *ClaimableBalanceLoader) Exec(ctx context.Context, session db.SessionInt
// https://github.com/stellar/go/issues/2370
sort.Strings(ids)
var rows []HistoryClaimableBalance
err := bulkInsert(
err := bulkGetOrCreate(
ctx,
q,
"history_claimable_balances",
[]bulkInsertField{
[]columnValues{
{
name: "claimable_balance_id",
dbType: "text",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ func (a *LiquidityPoolLoader) Exec(ctx context.Context, session db.SessionInterf
// https://github.com/stellar/go/issues/2370
sort.Strings(ids)
var rows []HistoryLiquidityPool
err := bulkInsert(
err := bulkGetOrCreate(
ctx,
q,
"history_liquidity_pools",
[]bulkInsertField{
[]columnValues{
{
name: "liquidity_pool_id",
dbType: "text",
Expand Down

0 comments on commit 877cfb4

Please sign in to comment.