asyncio.sleep less often
This commit is contained in:
parent
cb1ed3beb1
commit
e9f2b1efea
1 changed files with 11 additions and 5 deletions
|
@ -606,25 +606,31 @@ class SessionManager:
|
|||
needed_tx_infos = []
|
||||
append_needed_tx_info = needed_tx_infos.append
|
||||
tx_infos = {}
|
||||
cnt = 0
|
||||
for tx_num in tx_nums:
|
||||
cached = self.history_tx_info_cache.get(tx_num)
|
||||
if cached is not None:
|
||||
tx_infos[tx_num] = cached
|
||||
else:
|
||||
append_needed_tx_info(tx_num)
|
||||
cnt += 1
|
||||
if cnt % 1000 == 0:
|
||||
await asyncio.sleep(0)
|
||||
if needed_tx_infos:
|
||||
|
||||
for tx_num, tx_hash in zip(needed_tx_infos, await self.db.get_tx_hashes(needed_tx_infos)):
|
||||
hist = tx_hash[::-1].hex(), bisect_right(self.db.tx_counts, tx_num)
|
||||
tx_infos[tx_num] = self.history_tx_info_cache[tx_num] = hist
|
||||
cnt += 1
|
||||
if cnt % 1000 == 0:
|
||||
await asyncio.sleep(0)
|
||||
history = []
|
||||
history_append = history.append
|
||||
for tx_num in tx_nums:
|
||||
history_append(tx_infos[tx_num])
|
||||
await asyncio.sleep(0)
|
||||
self.hashX_full_cache[hashX] = history
|
||||
cnt += 1
|
||||
if cnt % 1000 == 0:
|
||||
await asyncio.sleep(0)
|
||||
return history
|
||||
|
||||
def _notify_peer(self, peer):
|
||||
|
|
Loading…
Reference in a new issue