Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/identifiers.py
Show First 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | def api_swhid_known(request): | ||||
swhids = [get_swhid(swhid) for swhid in request.data] | swhids = [get_swhid(swhid) for swhid in request.data] | ||||
response = {str(swhid): {"known": False} for swhid in swhids} | response = {str(swhid): {"known": False} for swhid in swhids} | ||||
# group swhids by their type | # group swhids by their type | ||||
swhids_by_type = group_swhids(swhids) | swhids_by_type = group_swhids(swhids) | ||||
# search for hashes not present in the storage | # search for hashes not present in the storage | ||||
missing_hashes = set( | missing_hashes = { | ||||
map(hash_to_bytes, archive.lookup_missing_hashes(swhids_by_type)) | k: set(map(hash_to_bytes, archive.lookup_missing_hashes({k: v}))) | ||||
) | for k, v in swhids_by_type.items() | ||||
} | |||||
for swhid in swhids: | for swhid in swhids: | ||||
if swhid.object_id not in missing_hashes: | if swhid.object_id not in missing_hashes[swhid.object_type]: | ||||
response[str(swhid)]["known"] = True | response[str(swhid)]["known"] = True | ||||
return response | return response |