read tx array with latest leftmost; remove duplicates keeping leftmost; limit to 1000 (the array provides 1100)
This commit is contained in:
parent
821c5e535d
commit
079d044935
|
@ -41,7 +41,7 @@ def run_query(transaction_row_limit=50, filter_txsig=None):
|
|||
return maprows
|
||||
|
||||
|
||||
def query_transactions_by_address(account_key: str, transaction_row_limit=100):
|
||||
def query_transactions_by_address(account_key: str, transaction_row_limit=1000):
|
||||
maprows = postgres_connection.query(
|
||||
"""
|
||||
WITH tx_slot_data AS (
|
||||
|
@ -60,18 +60,23 @@ def query_transactions_by_address(account_key: str, transaction_row_limit=100):
|
|||
txi.cu_requested,
|
||||
txi.prioritization_fees,
|
||||
tx_slot_data.min_utc_timestamp AS utc_timestamp
|
||||
FROM banking_stage_results_2.accounts_map_transaction_latest amt_latest
|
||||
-- amt.tx_ids is an array of transaction_ids limited to 1000 (see sidecar LIMIT_LATEST_TXS_PER_ACCOUNT)
|
||||
INNER JOIN unnest(amt_latest.tx_ids) WITH ORDINALITY AS amt_txs(transaction_id, sort_nr) ON true
|
||||
INNER JOIN banking_stage_results_2.accounts acc ON acc.acc_id=amt_latest.acc_id
|
||||
FROM
|
||||
(
|
||||
-- unnest the array, remove duplicates keeping the first occurence (i.e. more recent transactions), the restore sort order and finally limit
|
||||
SELECT DISTINCT ON (acc_id,transaction_id) acc_id, transaction_id, sort_nr FROM (
|
||||
SELECT acc_id, unnested.transaction_id, unnested.sort_nr
|
||||
FROM banking_stage_results_2.accounts_map_transaction_latest amt_latest,
|
||||
unnest(amt_latest.tx_ids) WITH ORDINALITY AS unnested(transaction_id, sort_nr)
|
||||
WHERE amt_latest.acc_id IN (SELECT acc_id FROM banking_stage_results_2.accounts WHERE account_key=%s)
|
||||
)
|
||||
) as amt_txs
|
||||
INNER JOIN banking_stage_results_2.transactions txs ON txs.transaction_id=amt_txs.transaction_id
|
||||
LEFT JOIN tx_slot_data ON tx_slot_data.transaction_id=amt_txs.transaction_id
|
||||
LEFT JOIN banking_stage_results_2.transaction_infos txi ON txi.transaction_id=amt_txs.transaction_id
|
||||
WHERE true
|
||||
-- note: check for txi is actually useless ATM as txi is always updated aling with amt_latest
|
||||
AND (tx_slot_data IS NOT NULL OR txi IS NOT NULL)
|
||||
AND account_key = %s
|
||||
ORDER BY sort_nr DESC
|
||||
ORDER BY sort_nr
|
||||
LIMIT %s
|
||||
""", [
|
||||
account_key,
|
||||
|
|
Loading…
Reference in New Issue