shift optimization to DataStore.get_keys_values_dict()

This commit is contained in:
Kyle Altendorf 2023-07-11 15:14:25 -04:00
parent a5e8db7888
commit b12ae08e3b
No known key found for this signature in database

View File

@ -762,6 +762,9 @@ class DataStore:
)
async def get_keys_values_dict(self, tree_id: bytes32, root_hash: Optional[bytes32] = None) -> Dict[bytes, bytes]:
if root_hash is None:
return {}
pairs = await self.get_keys_values(tree_id=tree_id, root_hash=root_hash)
return {node.key: node.value for node in pairs}
@ -1015,11 +1018,7 @@ class DataStore:
) -> Optional[bytes32]:
async with self.db_wrapper.writer():
old_root = await self.get_tree_root(tree_id)
root_hash = old_root.node_hash
if old_root.node_hash is None:
hint_keys_values = {}
else:
hint_keys_values = await self.get_keys_values_dict(tree_id, root_hash=root_hash)
hint_keys_values = await self.get_keys_values_dict(tree_id, root_hash=old_root.node_hash)
iter_root: Optional[Root] = old_root
for change in changelist: