Skip to content

Commit

Permalink
remove unnecssary parentheses in joins
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 committed Nov 1, 2024
1 parent 3da3303 commit 76120c0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions persist/sqlite/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ WHERE ev.event_id = ?`, eventID).Scan(decode(&m.SiacoinOutput.StateElement.ID),
var m explorer.EventMinerPayout
err = tx.QueryRow(`SELECT sc.output_id, sc.leaf_index, sc.maturity_height, sc.address, sc.value
FROM siacoin_elements sc
INNER JOIN miner_payout_events ev ON (ev.output_id = sc.id)
INNER JOIN miner_payout_events ev ON ev.output_id = sc.id
WHERE ev.event_id = ?`, eventID).Scan(decode(&m.SiacoinOutput.StateElement.ID), decode(&m.SiacoinOutput.StateElement.LeafIndex), decode(&m.SiacoinOutput.MaturityHeight), decode(&m.SiacoinOutput.SiacoinOutput.Address), decode(&m.SiacoinOutput.SiacoinOutput.Value))
if err != nil {
return explorer.Event{}, 0, fmt.Errorf("failed to fetch miner payout event data: %w", err)
Expand All @@ -85,7 +85,7 @@ WHERE ev.event_id = ?`, eventID).Scan(decode(&m.SiacoinOutput.StateElement.ID),
var m explorer.EventFoundationSubsidy
err = tx.QueryRow(`SELECT sc.output_id, sc.leaf_index, sc.maturity_height, sc.address, sc.value
FROM siacoin_elements sc
INNER JOIN foundation_subsidy_events ev ON (ev.output_id = sc.id)
INNER JOIN foundation_subsidy_events ev ON ev.output_id = sc.id
WHERE ev.event_id = ?`, eventID).Scan(decode(&m.SiacoinOutput.StateElement.ID), decode(&m.SiacoinOutput.StateElement.LeafIndex), decode(&m.SiacoinOutput.MaturityHeight), decode(&m.SiacoinOutput.SiacoinOutput.Address), decode(&m.SiacoinOutput.SiacoinOutput.Value))
ev.Data = &m
default:
Expand Down Expand Up @@ -153,8 +153,8 @@ func (s *Store) AddressEvents(address types.Address, offset, limit uint64) (even
err = s.transaction(func(tx *txn) error {
const query = `SELECT ev.id, ev.event_id, ev.maturity_height, ev.date_created, ev.height, ev.block_id, ev.event_type
FROM events ev
INNER JOIN event_addresses ea ON (ev.id = ea.event_id)
INNER JOIN address_balance sa ON (ea.address_id = sa.id)
INNER JOIN event_addresses ea ON ev.id = ea.event_id
INNER JOIN address_balance sa ON ea.address_id = sa.id
WHERE sa.address = $1
ORDER BY ev.maturity_height DESC, ev.id DESC
LIMIT $2 OFFSET $3`
Expand Down
6 changes: 3 additions & 3 deletions persist/sqlite/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *Store) Contracts(ids []types.FileContractID) (result []explorer.FileCon
err = s.transaction(func(tx *txn) error {
query := `SELECT fc1.id, fc1.contract_id, fc1.leaf_index, fc1.resolved, fc1.valid, fc1.transaction_id, rev.confirmation_index, rev.confirmation_transaction_id, rev.proof_index, rev.proof_transaction_id, fc1.filesize, fc1.file_merkle_root, fc1.window_start, fc1.window_end, fc1.payout, fc1.unlock_hash, fc1.revision_number
FROM file_contract_elements fc1
INNER JOIN last_contract_revision rev ON (rev.contract_element_id = fc1.id)
INNER JOIN last_contract_revision rev ON rev.contract_element_id = fc1.id
WHERE rev.contract_id IN (` + queryPlaceHolders(len(ids)) + `)`
rows, err := tx.Query(query, encodedIDs(ids)...)
if err != nil {
Expand Down Expand Up @@ -86,7 +86,7 @@ func (s *Store) ContractRevisions(id types.FileContractID) (revisions []explorer
err = s.transaction(func(tx *txn) error {
query := `SELECT fc.id, fc.contract_id, fc.leaf_index, fc.resolved, fc.valid, fc.transaction_id, rev.confirmation_index, rev.confirmation_transaction_id, rev.proof_index, rev.proof_transaction_id, fc.filesize, fc.file_merkle_root, fc.window_start, fc.window_end, fc.payout, fc.unlock_hash, fc.revision_number
FROM file_contract_elements fc
JOIN last_contract_revision rev ON (rev.contract_id = fc.contract_id)
JOIN last_contract_revision rev ON rev.contract_id = fc.contract_id
WHERE fc.contract_id = ?
ORDER BY fc.revision_number ASC`
rows, err := tx.Query(query, encode(id))
Expand Down Expand Up @@ -144,7 +144,7 @@ func (s *Store) ContractsKey(key types.PublicKey) (result []explorer.FileContrac
err = s.transaction(func(tx *txn) error {
query := `SELECT fc1.id, fc1.contract_id, fc1.leaf_index, fc1.resolved, fc1.valid, fc1.transaction_id, rev.confirmation_index, rev.confirmation_transaction_id, rev.proof_index, rev.proof_transaction_id, fc1.filesize, fc1.file_merkle_root, fc1.window_start, fc1.window_end, fc1.payout, fc1.unlock_hash, fc1.revision_number
FROM file_contract_elements fc1
INNER JOIN last_contract_revision rev ON (rev.contract_element_id = fc1.id)
INNER JOIN last_contract_revision rev ON rev.contract_element_id = fc1.id
WHERE rev.ed25519_renter_key = ? OR rev.ed25519_host_key = ?`
rows, err := tx.Query(query, encode(key), encode(key))
if err != nil {
Expand Down
24 changes: 12 additions & 12 deletions persist/sqlite/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
func (s *Store) TransactionChainIndices(txnID types.TransactionID, offset, limit uint64) (indices []types.ChainIndex, err error) {
err = s.transaction(func(tx *txn) error {
rows, err := tx.Query(`SELECT DISTINCT b.id, b.height FROM blocks b
INNER JOIN block_transactions bt ON (bt.block_id = b.id)
INNER JOIN transactions t ON (t.id = bt.transaction_id)
INNER JOIN block_transactions bt ON bt.block_id = b.id
INNER JOIN transactions t ON t.id = bt.transaction_id
WHERE t.transaction_id = ?
ORDER BY b.height DESC
LIMIT ? OFFSET ?`, encode(txnID), limit, offset)
Expand Down Expand Up @@ -112,7 +112,7 @@ ORDER BY transaction_order ASC`
func transactionSiacoinOutputs(tx *txn, txnIDs []int64) (map[int64][]explorer.SiacoinOutput, error) {
query := `SELECT ts.transaction_id, sc.output_id, sc.leaf_index, sc.spent_index, sc.source, sc.maturity_height, sc.address, sc.value
FROM siacoin_elements sc
INNER JOIN transaction_siacoin_outputs ts ON (ts.output_id = sc.id)
INNER JOIN transaction_siacoin_outputs ts ON ts.output_id = sc.id
WHERE ts.transaction_id IN (` + queryPlaceHolders(len(txnIDs)) + `)
ORDER BY ts.transaction_order ASC`
rows, err := tx.Query(query, queryArgs(txnIDs)...)
Expand Down Expand Up @@ -142,7 +142,7 @@ ORDER BY ts.transaction_order ASC`
func transactionSiacoinInputs(tx *txn, txnIDs []int64) (map[int64][]explorer.SiacoinInput, error) {
query := `SELECT sc.id, ts.transaction_id, sc.output_id, ts.unlock_conditions, sc.value
FROM siacoin_elements sc
INNER JOIN transaction_siacoin_inputs ts ON (ts.parent_id = sc.id)
INNER JOIN transaction_siacoin_inputs ts ON ts.parent_id = sc.id
WHERE ts.transaction_id IN (` + queryPlaceHolders(len(txnIDs)) + `)
ORDER BY ts.transaction_order ASC`
rows, err := tx.Query(query, queryArgs(txnIDs)...)
Expand All @@ -168,7 +168,7 @@ ORDER BY ts.transaction_order ASC`
func transactionSiafundInputs(tx *txn, txnIDs []int64) (map[int64][]explorer.SiafundInput, error) {
query := `SELECT ts.transaction_id, sf.output_id, ts.unlock_conditions, ts.claim_address, sf.value
FROM siafund_elements sf
INNER JOIN transaction_siafund_inputs ts ON (ts.parent_id = sf.id)
INNER JOIN transaction_siafund_inputs ts ON ts.parent_id = sf.id
WHERE ts.transaction_id IN (` + queryPlaceHolders(len(txnIDs)) + `)
ORDER BY ts.transaction_order ASC`
rows, err := tx.Query(query, queryArgs(txnIDs)...)
Expand All @@ -195,7 +195,7 @@ ORDER BY ts.transaction_order ASC`
func transactionSiafundOutputs(tx *txn, txnIDs []int64) (map[int64][]explorer.SiafundOutput, error) {
query := `SELECT ts.transaction_id, sf.output_id, sf.leaf_index, sf.spent_index, sf.claim_start, sf.address, sf.value
FROM siafund_elements sf
INNER JOIN transaction_siafund_outputs ts ON (ts.output_id = sf.id)
INNER JOIN transaction_siafund_outputs ts ON ts.output_id = sf.id
WHERE ts.transaction_id IN (` + queryPlaceHolders(len(txnIDs)) + `)
ORDER BY ts.transaction_order ASC`
rows, err := tx.Query(query, queryArgs(txnIDs)...)
Expand Down Expand Up @@ -286,8 +286,8 @@ type contractOrder struct {
func transactionFileContracts(tx *txn, txnIDs []int64) (map[int64][]explorer.FileContract, error) {
query := `SELECT ts.transaction_id, fc.id, rev.confirmation_index, rev.confirmation_transaction_id, rev.proof_index, rev.proof_transaction_id, fc.contract_id, fc.leaf_index, fc.resolved, fc.valid, fc.transaction_id, fc.filesize, fc.file_merkle_root, fc.window_start, fc.window_end, fc.payout, fc.unlock_hash, fc.revision_number
FROM file_contract_elements fc
INNER JOIN transaction_file_contracts ts ON (ts.contract_id = fc.id)
INNER JOIN last_contract_revision rev ON (rev.contract_id = fc.contract_id)
INNER JOIN transaction_file_contracts ts ON ts.contract_id = fc.id
INNER JOIN last_contract_revision rev ON rev.contract_id = fc.contract_id
WHERE ts.transaction_id IN (` + queryPlaceHolders(len(txnIDs)) + `)
ORDER BY ts.transaction_order ASC`
rows, err := tx.Query(query, queryArgs(txnIDs)...)
Expand Down Expand Up @@ -347,8 +347,8 @@ ORDER BY ts.transaction_order ASC`
func transactionFileContractRevisions(tx *txn, txnIDs []int64) (map[int64][]explorer.FileContractRevision, error) {
query := `SELECT ts.transaction_id, fc.id, rev.confirmation_index, rev.confirmation_transaction_id, rev.proof_index, rev.proof_transaction_id, ts.parent_id, ts.unlock_conditions, fc.contract_id, fc.leaf_index, fc.resolved, fc.valid, fc.transaction_id, fc.filesize, fc.file_merkle_root, fc.window_start, fc.window_end, fc.payout, fc.unlock_hash, fc.revision_number
FROM file_contract_elements fc
INNER JOIN transaction_file_contract_revisions ts ON (ts.contract_id = fc.id)
INNER JOIN last_contract_revision rev ON (rev.contract_id = fc.contract_id)
INNER JOIN transaction_file_contract_revisions ts ON ts.contract_id = fc.id
INNER JOIN last_contract_revision rev ON rev.contract_id = fc.contract_id
WHERE ts.transaction_id IN (` + queryPlaceHolders(len(txnIDs)) + `)
ORDER BY ts.transaction_order ASC`
rows, err := tx.Query(query, queryArgs(txnIDs)...)
Expand Down Expand Up @@ -442,7 +442,7 @@ type transactionID struct {
func blockTransactionIDs(tx *txn, blockID types.BlockID) (idMap map[int64]transactionID, err error) {
rows, err := tx.Query(`SELECT bt.transaction_id, block_order, t.transaction_id
FROM block_transactions bt
INNER JOIN transactions t ON (t.id = bt.transaction_id)
INNER JOIN transactions t ON t.id = bt.transaction_id
WHERE block_id = ? ORDER BY block_order ASC`, encode(blockID))
if err != nil {
return nil, err
Expand All @@ -466,7 +466,7 @@ WHERE block_id = ? ORDER BY block_order ASC`, encode(blockID))
func blockMinerPayouts(tx *txn, blockID types.BlockID) ([]explorer.SiacoinOutput, error) {
query := `SELECT sc.output_id, sc.leaf_index, sc.spent_index, sc.source, sc.maturity_height, sc.address, sc.value
FROM siacoin_elements sc
INNER JOIN miner_payouts mp ON (mp.output_id = sc.id)
INNER JOIN miner_payouts mp ON mp.output_id = sc.id
WHERE mp.block_id = ?
ORDER BY mp.block_order ASC`
rows, err := tx.Query(query, encode(blockID))
Expand Down
6 changes: 3 additions & 3 deletions persist/sqlite/v2contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *Store) V2Contracts(ids []types.FileContractID) (result []explorer.V2Fil
err = s.transaction(func(tx *txn) error {
stmt, err := tx.Prepare(`SELECT fc.transaction_id, rev.confirmation_index, rev.confirmation_transaction_id, rev.resolution, rev.resolution_index, rev.resolution_transaction_id, fc.contract_id, fc.leaf_index, fc.capacity, fc.filesize, fc.file_merkle_root, fc.proof_height, fc.expiration_height, fc.renter_output_address, fc.renter_output_value, fc.host_output_address, fc.host_output_value, fc.missed_host_value, fc.total_collateral, fc.renter_public_key, fc.host_public_key, fc.revision_number, fc.renter_signature, fc.host_signature
FROM v2_last_contract_revision rev
INNER JOIN v2_file_contract_elements fc ON (rev.contract_element_id = fc.id)
INNER JOIN v2_file_contract_elements fc ON rev.contract_element_id = fc.id
WHERE rev.contract_id = ?
`)
if err != nil {
Expand All @@ -68,7 +68,7 @@ func (s *Store) V2ContractRevisions(id types.FileContractID) (revisions []explor
err = s.transaction(func(tx *txn) error {
query := `SELECT fc.transaction_id, rev.confirmation_index, rev.confirmation_transaction_id, rev.resolution, rev.resolution_index, rev.resolution_transaction_id, fc.contract_id, fc.leaf_index, fc.capacity, fc.filesize, fc.file_merkle_root, fc.proof_height, fc.expiration_height, fc.renter_output_address, fc.renter_output_value, fc.host_output_address, fc.host_output_value, fc.missed_host_value, fc.total_collateral, fc.renter_public_key, fc.host_public_key, fc.revision_number, fc.renter_signature, fc.host_signature
FROM v2_file_contract_elements fc
INNER JOIN v2_last_contract_revision rev ON (rev.contract_id = fc.contract_id)
INNER JOIN v2_last_contract_revision rev ON rev.contract_id = fc.contract_id
WHERE fc.contract_id = ?
ORDER BY fc.revision_number ASC
`
Expand Down Expand Up @@ -101,7 +101,7 @@ func (s *Store) V2ContractsKey(key types.PublicKey) (result []explorer.V2FileCon
encoded := encode(key)
rows, err := tx.Query(`SELECT fc.transaction_id, rev.confirmation_index, rev.confirmation_transaction_id, rev.resolution, rev.resolution_index, rev.resolution_transaction_id, fc.contract_id, fc.leaf_index, fc.capacity, fc.filesize, fc.file_merkle_root, fc.proof_height, fc.expiration_height, fc.renter_output_address, fc.renter_output_value, fc.host_output_address, fc.host_output_value, fc.missed_host_value, fc.total_collateral, fc.renter_public_key, fc.host_public_key, fc.revision_number, fc.renter_signature, fc.host_signature
FROM v2_last_contract_revision rev
INNER JOIN v2_file_contract_elements fc ON (rev.contract_element_id = fc.id)
INNER JOIN v2_file_contract_elements fc ON rev.contract_element_id = fc.id
WHERE fc.renter_public_key = ? OR fc.host_public_key = ?
ORDER BY rev.confirmation_index ASC
`, encoded, encoded)
Expand Down

0 comments on commit 76120c0

Please sign in to comment.