Skip to content

Commit

Permalink
feat: remove transaction from Upsert query
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-4chain committed Sep 10, 2024
1 parent 822575a commit eb4345e
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions internal/blocktx/store/postgresql/upsert_block_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,12 @@ func (p *PostgreSQL) UpsertBlockTransactions(ctx context.Context, blockId uint64
WHERE m.blockid = $1 AND t.is_registered = TRUE
`

dbTx, err := p.db.Begin()
if err != nil {
return nil, err
}
defer func() {
_ = dbTx.Rollback()
}()

_, err = dbTx.ExecContext(ctx, qUpsertTransactions, blockId, pq.Array(txHashesBytes), pq.Array(merklePaths))
_, err := p.db.ExecContext(ctx, qUpsertTransactions, blockId, pq.Array(txHashesBytes), pq.Array(merklePaths))
if err != nil {
return nil, fmt.Errorf("failed to execute transactions upsert query: %v", err)
}

rows, err := dbTx.QueryContext(ctx, qRegisteredTransactions, blockId)
rows, err := p.db.QueryContext(ctx, qRegisteredTransactions, blockId)
if err != nil {
return nil, fmt.Errorf("failed to get registered transactions for block with id %d: %v", blockId, err)
}
Expand All @@ -90,10 +82,5 @@ func (p *PostgreSQL) UpsertBlockTransactions(ctx context.Context, blockId uint64
return nil, fmt.Errorf("error getting registered transactions for block with id %d: %v", blockId, err)
}

err = dbTx.Commit()
if err != nil {
return nil, err
}

return registeredRows, nil
}

0 comments on commit eb4345e

Please sign in to comment.