Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slow SQL queries #4

Merged
merged 2 commits into from
Dec 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions Mce/DataStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -3780,8 +3780,10 @@ def get_number_of_addresses(store, chain):
"""
result = -1
countrow = store.selectrow("""
SELECT COUNT(DISTINCT(pubkey_hash)) FROM txout_detail WHERE chain_id = ?
""", (chain.id,))
SELECT COUNT(DISTINCT(pubkey.pubkey_hash))
FROM txout
LEFT JOIN pubkey ON (txout.pubkey_id = pubkey.pubkey_id)
""")
if countrow:
result = countrow[0]
if result > 0:
Expand Down Expand Up @@ -3940,12 +3942,14 @@ def get_recent_transactions_as_json(store, chain, limit=10):
"""
# Ignore coinbase transactions where there is no native currency
rows = store.selectall("""
SELECT DISTINCT tx_hash
FROM txout_detail
WHERE chain_id=? AND pubkey_id != ?
ORDER BY block_height DESC, tx_id DESC
LIMIT ?
""", (chain.id, NULL_PUBKEY_ID, limit))
SELECT tx_hash
FROM tx
WHERE tx_id in (SELECT DISTINCT tx_id
FROM txout
WHERE pubkey_id != ?
ORDER BY tx_id DESC
LIMIT ?)
""", (NULL_PUBKEY_ID, limit))

if rows is None:
return []
Expand Down