Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/service.py
Show First 20 Lines • Show All 1,280 Lines • ▼ Show 20 Lines | raise BadInputExc( | ||||
( | ( | ||||
"Invalid swh object type! Valid types are " | "Invalid swh object type! Valid types are " | ||||
f"{CONTENT}, {DIRECTORY}, {RELEASE} " | f"{CONTENT}, {DIRECTORY}, {RELEASE} " | ||||
f"{REVISION} or {SNAPSHOT}." | f"{REVISION} or {SNAPSHOT}." | ||||
) | ) | ||||
) | ) | ||||
def lookup_missing_hashes(grouped_pids: Dict[str, List[bytes]]) -> Set[str]: | def lookup_missing_hashes(grouped_swhids: Dict[str, List[bytes]]) -> Set[str]: | ||||
"""Lookup missing Software Heritage persistent identifier hash, using | """Lookup missing Software Heritage persistent identifier hash, using | ||||
batch processing. | batch processing. | ||||
Args: | Args: | ||||
A dictionary with: | A dictionary with: | ||||
keys: persistent identifier type | keys: object types | ||||
values: list(bytes) persistent identifier hash | values: object hashes | ||||
Returns: | Returns: | ||||
A set(hexadecimal) of the hashes not found in the storage | A set(hexadecimal) of the hashes not found in the storage | ||||
""" | """ | ||||
missing_hashes = [] | missing_hashes = [] | ||||
for obj_type, obj_ids in grouped_pids.items(): | for obj_type, obj_ids in grouped_swhids.items(): | ||||
if obj_type == CONTENT: | if obj_type == CONTENT: | ||||
missing_hashes.append(storage.content_missing_per_sha1_git(obj_ids)) | missing_hashes.append(storage.content_missing_per_sha1_git(obj_ids)) | ||||
elif obj_type == DIRECTORY: | elif obj_type == DIRECTORY: | ||||
missing_hashes.append(storage.directory_missing(obj_ids)) | missing_hashes.append(storage.directory_missing(obj_ids)) | ||||
elif obj_type == REVISION: | elif obj_type == REVISION: | ||||
missing_hashes.append(storage.revision_missing(obj_ids)) | missing_hashes.append(storage.revision_missing(obj_ids)) | ||||
elif obj_type == RELEASE: | elif obj_type == RELEASE: | ||||
missing_hashes.append(storage.directory_missing(obj_ids)) | missing_hashes.append(storage.directory_missing(obj_ids)) | ||||
elif obj_type == SNAPSHOT: | elif obj_type == SNAPSHOT: | ||||
missing_hashes.append(storage.directory_missing(obj_ids)) | missing_hashes.append(storage.directory_missing(obj_ids)) | ||||
missing = set( | missing = set( | ||||
map(lambda x: hashutil.hash_to_hex(x), itertools.chain(*missing_hashes)) | map(lambda x: hashutil.hash_to_hex(x), itertools.chain(*missing_hashes)) | ||||
) | ) | ||||
return missing | return missing |