casync: build_chunk_dict optimize for resuming (#25038)

old-commit-hash: 06a8ac627c0b8cf00b3bd4ea7186f5c876f71561
This commit is contained in:
Willem Melching
2022-07-05 18:06:08 +02:00
committed by GitHub
parent 3230474724
commit 0f37257d29

View File

@@ -123,8 +123,13 @@ def parse_caibx(caibx_path: str) -> List[Chunk]:
def build_chunk_dict(chunks: List[Chunk]) -> ChunkDict:
"""Turn a list of chunks into a dict for faster lookups based on hash"""
return {c.sha: c for c in chunks}
"""Turn a list of chunks into a dict for faster lookups based on hash.
Keep first chunk since it's more likely to be already downloaded."""
r = {}
for c in chunks:
if c.sha not in r:
r[c.sha] = c
return r
def extract(target: List[Chunk],