Skip to content

Commit 230e078

Browse files
committed
Optimize export count
- Postgres runs **3 complete SCANS** and aggregates in memory, not needed for a count. This way is more optimal even if doing 3 calls to the database
1 parent 6cff29e commit 230e078

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

safe_transaction_service/history/services/transaction_service.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -628,13 +628,9 @@ def get_export_transactions(
628628
).values("transaction_hash", "_log_index", "_trace_address")
629629

630630
total_count = (
631-
ether_transfers.union(erc20_transfers, all=True)
632-
.union(erc721_transfers, all=True)
633-
.count()
631+
ether_transfers.count() + erc20_transfers.count() + erc721_transfers.count()
634632
)
635-
636633
with connection.cursor() as cursor:
637-
638634
# Get the data
639635
cursor.execute(main_query, main_params)
640636
columns = [col[0] for col in cursor.description]

0 commit comments

Comments
 (0)