From 06a8ac627c0b8cf00b3bd4ea7186f5c876f71561 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Tue, 5 Jul 2022 18:06:08 +0200 Subject: [PATCH] casync: build_chunk_dict optimize for resuming (#25038) --- system/hardware/tici/casync.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/system/hardware/tici/casync.py b/system/hardware/tici/casync.py index e77f473636..b857c04795 100755 --- a/system/hardware/tici/casync.py +++ b/system/hardware/tici/casync.py @@ -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],