From f1d51eae7bab69b4166cb3c8c8eeace8aa103846 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Fri, 27 May 2022 14:05:43 -0400 Subject: [PATCH] add get_hashX_statuses, using multi_get --- hub/db/db.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hub/db/db.py b/hub/db/db.py index e2110d4..88b71d9 100644 --- a/hub/db/db.py +++ b/hub/db/db.py @@ -633,9 +633,28 @@ class SecondaryDB: if status: return status.hex() + def _get_hashX_statuses(self, hashXes: List[bytes]): + statuses = { + hashX: status + for hashX, status in zip(hashXes, self.prefix_db.hashX_mempool_status.multi_get( + [(hashX,) for hashX in hashXes], deserialize_value=False + )) if status is not None + } + if len(statuses) < len(hashXes): + statuses.update({ + hashX: status + for hashX, status in zip(hashXes, self.prefix_db.hashX_status.multi_get( + [(hashX,) for hashX in hashXes if hashX not in statuses], deserialize_value=False + )) if status is not None + }) + return [None if hashX not in statuses else statuses[hashX].hex() for hashX in hashXes] + async def get_hashX_status(self, hashX: bytes): return await asyncio.get_event_loop().run_in_executor(self._executor, self._get_hashX_status, hashX) + async def get_hashX_statuses(self, hashXes: List[bytes]): + return await asyncio.get_event_loop().run_in_executor(self._executor, self._get_hashX_statuses, hashXes) + def get_tx_hash(self, tx_num: int) -> bytes: if self._cache_all_tx_hashes: return self.total_transactions[tx_num]