asyncio.sleep less often

This commit is contained in:
Jack Robison 2022-05-20 11:32:39 -04:00
parent cb1ed3beb1
commit e9f2b1efea
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -606,25 +606,31 @@ class SessionManager:
needed_tx_infos = [] needed_tx_infos = []
append_needed_tx_info = needed_tx_infos.append append_needed_tx_info = needed_tx_infos.append
tx_infos = {} tx_infos = {}
cnt = 0
for tx_num in tx_nums: for tx_num in tx_nums:
cached = self.history_tx_info_cache.get(tx_num) cached = self.history_tx_info_cache.get(tx_num)
if cached is not None: if cached is not None:
tx_infos[tx_num] = cached tx_infos[tx_num] = cached
else: else:
append_needed_tx_info(tx_num) append_needed_tx_info(tx_num)
await asyncio.sleep(0) cnt += 1
if cnt % 1000 == 0:
await asyncio.sleep(0)
if needed_tx_infos: if needed_tx_infos:
for tx_num, tx_hash in zip(needed_tx_infos, await self.db.get_tx_hashes(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) 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 tx_infos[tx_num] = self.history_tx_info_cache[tx_num] = hist
await asyncio.sleep(0) cnt += 1
if cnt % 1000 == 0:
await asyncio.sleep(0)
history = [] history = []
history_append = history.append history_append = history.append
for tx_num in tx_nums: for tx_num in tx_nums:
history_append(tx_infos[tx_num]) history_append(tx_infos[tx_num])
await asyncio.sleep(0) self.hashX_full_cache[hashX] = history
self.hashX_full_cache[hashX] = history cnt += 1
if cnt % 1000 == 0:
await asyncio.sleep(0)
return history return history
def _notify_peer(self, peer): def _notify_peer(self, peer):