faster read_claim_txos

This commit is contained in:
Jack Robison 2021-09-21 12:22:26 -04:00
parent 37ec9ab464
commit 72500f6948
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 7 additions and 5 deletions

View file

@ -44,6 +44,8 @@ class PrefixRow(metaclass=PrefixRowType):
def iterate(self, prefix=None, start=None, stop=None, def iterate(self, prefix=None, start=None, stop=None,
reverse: bool = False, include_key: bool = True, include_value: bool = True): reverse: bool = False, include_key: bool = True, include_value: bool = True):
if not prefix and not start and not stop:
prefix = ()
if prefix is not None: if prefix is not None:
prefix = self.pack_partial_key(*prefix) prefix = self.pack_partial_key(*prefix)
if start is not None: if start is not None:

View file

@ -851,11 +851,11 @@ class LevelDB:
async def _read_claim_txos(self): async def _read_claim_txos(self):
def read_claim_txos(): def read_claim_txos():
for _k, _v in self.db.iterator(prefix=Prefixes.claim_to_txo.prefix): set_txo_to_claim = self.txo_to_claim.__setitem__
k = Prefixes.claim_to_txo.unpack_key(_k) set_claim_to_txo = self.claim_to_txo.__setitem__
v = Prefixes.claim_to_txo.unpack_value(_v) for k, v in self.prefix_db.claim_to_txo.iterate():
self.claim_to_txo[k.claim_hash] = v set_claim_to_txo(k.claim_hash, v)
self.txo_to_claim[(v.tx_num, v.position)] = k.claim_hash set_txo_to_claim((v.tx_num, v.position), k.claim_hash)
self.claim_to_txo.clear() self.claim_to_txo.clear()
self.txo_to_claim.clear() self.txo_to_claim.clear()