Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize missing hashes lookup. #19126

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply review comments.
  • Loading branch information
fchirica committed Jan 13, 2025
commit f1d33e5adbf447e25c857a816039744ba449e6e5
8 changes: 4 additions & 4 deletions chia/data_layer/data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
)
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.util.db_wrapper import SQLITE_MAX_VARIABLE_NUMBER, DBWrapper2
from chia.util.batches import to_batches
from chia.util.lru_cache import LRUCache

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -237,17 +238,16 @@ async def insert_into_data_store_from_file(
found_hashes: set[bytes32] = set()

async with self.db_wrapper.reader() as reader:
for i in range(0, len(missing_hashes), batch_size):
batch = missing_hashes[i : i + batch_size]
placeholders = ",".join("?" for _ in batch)
for batch in to_batches(missing_hashes, batch_size):
placeholders = ",".join(["?"] * len(batch.entries))
query = f"""
SELECT hash, root_hash, idx
FROM nodes
WHERE store_id = ? AND hash IN ({placeholders})
LIMIT {len(placeholders)}
"""

async with reader.execute(query, (store_id, *batch)) as cursor:
async with reader.execute(query, (store_id, *batch.entries)) as cursor:
rows = await cursor.fetchall()
for row in rows:
node_hash = bytes32(row["hash"])
Expand Down
Loading