mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2026-08-24 10:05:29 -05:00
Speedup WalletTransactionStore's _get_new_tx_records_from_old (#17529)
Speedup WalletTransactionStore's _get_new_tx_records_from_old.
This commit is contained in:
@@ -426,27 +426,42 @@ class WalletTransactionStore:
|
||||
).close()
|
||||
|
||||
async def _get_new_tx_records_from_old(self, old_records: List[TransactionRecordOld]) -> List[TransactionRecord]:
|
||||
tx_id_to_valid_times: Dict[bytes, ConditionValidTimes] = {}
|
||||
empty_valid_times = ConditionValidTimes()
|
||||
async with self.db_wrapper.reader_no_transaction() as conn:
|
||||
valid_times: Dict[bytes32, ConditionValidTimes] = {}
|
||||
chunked_records: List[List[TransactionRecordOld]] = [
|
||||
old_records[i : min(len(old_records), i + self.db_wrapper.host_parameter_limit)]
|
||||
for i in range(0, len(old_records), self.db_wrapper.host_parameter_limit)
|
||||
]
|
||||
for records_chunk in chunked_records:
|
||||
cursor = await conn.execute(
|
||||
f"SELECT txid, valid_times from tx_times WHERE txid IN ({','.join('?' * len(records_chunk))})",
|
||||
f"SELECT txid, valid_times from tx_times WHERE txid IN ({','.join('?' * len(records_chunk))})",
|
||||
tuple(tx.name for tx in records_chunk),
|
||||
)
|
||||
valid_times = {
|
||||
**valid_times,
|
||||
**{bytes32(res[0]): ConditionValidTimes.from_bytes(res[1]) for res in await cursor.fetchall()},
|
||||
}
|
||||
for row in await cursor.fetchall():
|
||||
tx_id_to_valid_times[row[0]] = ConditionValidTimes.from_bytes(row[1])
|
||||
await cursor.close()
|
||||
return [
|
||||
TransactionRecord(
|
||||
valid_times=valid_times[record.name] if record.name in valid_times else ConditionValidTimes(),
|
||||
confirmed_at_height=record.confirmed_at_height,
|
||||
created_at_time=record.created_at_time,
|
||||
to_puzzle_hash=record.to_puzzle_hash,
|
||||
amount=record.amount,
|
||||
fee_amount=record.fee_amount,
|
||||
confirmed=record.confirmed,
|
||||
sent=record.sent,
|
||||
spend_bundle=record.spend_bundle,
|
||||
**{k: v for k, v in dataclasses.asdict(record).items() if k != "spend_bundle"},
|
||||
additions=record.additions,
|
||||
removals=record.removals,
|
||||
wallet_id=record.wallet_id,
|
||||
sent_to=record.sent_to,
|
||||
trade_id=record.trade_id,
|
||||
type=record.type,
|
||||
name=record.name,
|
||||
memos=record.memos,
|
||||
valid_times=(
|
||||
tx_id_to_valid_times[record.name] if record.name in tx_id_to_valid_times else empty_valid_times
|
||||
),
|
||||
)
|
||||
for record in old_records
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user