make query stable

This commit is contained in:
GroovieGermanikus 2023-12-15 18:02:05 +01:00
parent ecd3d875ab
commit 57cfb01ede
No known key found for this signature in database
GPG Key ID: 5B6EB831A5CD2015
4 changed files with 17 additions and 17 deletions

View File

@ -2,24 +2,23 @@ import transaction_database
import postgres_connection
import json
def build_account_details(pubkey: str):
def build_account_details(pubkey: str, recent_blocks_row_limit=10):
(transactions, is_limit_exceeded) = list(transaction_database.query_transactions_by_address(pubkey))
account = {}
account['pubkey'] = pubkey
account = {'pubkey': pubkey}
blocks = postgres_connection.query(
"""
SELECT * FROM (
SELECT
slot,
total_cu_consumed,
prioritization_fees_info
FROM banking_stage_results_2.accounts_map_blocks
WHERE acc_id = (select acc_id from banking_stage_results_2.accounts where account_key = %s) and is_write_locked = true
order by slot desc
limit 10
) AS data
""", args=[pubkey])
FROM banking_stage_results_2.accounts_map_blocks b
INNER JOIN banking_stage_results_2.accounts acc ON acc.acc_id=b.acc_id
WHERE b.is_write_locked AND account_key = %s
ORDER BY slot DESC
limit %s
""", args=[pubkey, recent_blocks_row_limit])
for row in blocks:
pf = json.loads(row['prioritization_fees_info'])
row['min'] = pf['min']
@ -28,8 +27,7 @@ def build_account_details(pubkey: str):
row['p75'] = pf['p75']
row['p90'] = pf['p90']
row['p95'] = pf['p95']
account['blocks'] = blocks
return (account, transactions, is_limit_exceeded)
return account, blocks, transactions, is_limit_exceeded
def main():
build_account_details('AfASDKLEWG7Di9HtZDmHKftR1fsMXBtTSxP7qMo9qv7L')

4
app.py
View File

@ -94,11 +94,11 @@ def get_account(pubkey):
if not is_b58_44(pubkey):
return "Invalid account", 404
start = time.time()
(account, transactions, is_limit_exceeded) = account_details_database.build_account_details(pubkey)
(account, blocks, transactions, is_limit_exceeded) = account_details_database.build_account_details(pubkey, recent_blocks_row_limit=10)
elapsed = time.time() - start
if elapsed > .5:
print("account_details_database.build_account_details() took", elapsed, "seconds")
return render_template('account_details.html', config=this_config, account=account, transactions=transactions, limit_exceeded=is_limit_exceeded)
return render_template('account_details.html', config=this_config, account=account, recent_blocks=blocks, transactions=transactions, limit_exceeded=is_limit_exceeded)
def is_slot_number(raw_string):

View File

@ -64,7 +64,7 @@
</tr>
</thead>
<tbody>
{% for block in account.blocks %}
{% for block in recent_blocks %}
<tr>
<td>
<a hx-boost="false" href="/block/{{block.slot}}">

View File

@ -16,7 +16,8 @@ def run_query(transaction_row_limit=None, filter_txsig=None, filter_account_addr
( txi is not null ) AS was_included_in_block,
txi.cu_requested,
txi.prioritization_fees,
utc_timestamp
utc_timestamp,
tx_slot.transaction_id
FROM banking_stage_results_2.transaction_slot tx_slot
INNER JOIN banking_stage_results_2.transactions txs ON txs.transaction_id=tx_slot.transaction_id
LEFT JOIN banking_stage_results_2.transaction_infos txi ON txi.transaction_id=tx_slot.transaction_id
@ -29,7 +30,8 @@ def run_query(transaction_row_limit=None, filter_txsig=None, filter_account_addr
WHERE account_key = %s
))
) AS data
ORDER BY utc_timestamp DESC
-- transaction_id is required as tie breaker
ORDER BY utc_timestamp, transaction_id DESC
LIMIT %s
""", [
filter_txsig is None, filter_txsig,