Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/storage.py
Show First 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | ) -> Dict[bytes, List[Dict]]: | ||||
result: Dict[bytes, List[Dict]] = {sha1: [] for sha1 in contents} | result: Dict[bytes, List[Dict]] = {sha1: [] for sha1 in contents} | ||||
for row in db.content_get_metadata_from_sha1s(contents, cur): | for row in db.content_get_metadata_from_sha1s(contents, cur): | ||||
content_meta = dict(zip(db.content_get_metadata_keys, row)) | content_meta = dict(zip(db.content_get_metadata_keys, row)) | ||||
result[content_meta["sha1"]].append(content_meta) | result[content_meta["sha1"]].append(content_meta) | ||||
return result | return result | ||||
@timed | @timed | ||||
@db_transaction_generator() | @db_transaction_generator() | ||||
def content_missing(self, content, key_hash="sha1", db=None, cur=None): | def content_missing( | ||||
keys = db.content_hash_keys | self, contents: List[Dict[str, Any]], key_hash: str = "sha1", db=None, cur=None | ||||
) -> Iterable[bytes]: | |||||
if key_hash not in keys: | if key_hash not in DEFAULT_ALGORITHMS: | ||||
raise StorageArgumentException("key_hash should be one of %s" % keys) | raise StorageArgumentException( | ||||
"key_hash should be one of {','.join(DEFAULT_ALGORITHMS)}" | |||||
) | |||||
keys = db.content_hash_keys | |||||
key_hash_idx = keys.index(key_hash) | key_hash_idx = keys.index(key_hash) | ||||
if not content: | for obj in db.content_missing_from_list(contents, cur): | ||||
return | |||||
for obj in db.content_missing_from_list(content, cur): | |||||
yield obj[key_hash_idx] | yield obj[key_hash_idx] | ||||
@timed | @timed | ||||
@db_transaction_generator() | @db_transaction_generator() | ||||
def content_missing_per_sha1(self, contents, db=None, cur=None): | def content_missing_per_sha1(self, contents, db=None, cur=None): | ||||
for obj in db.content_missing_per_sha1(contents, cur): | for obj in db.content_missing_per_sha1(contents, cur): | ||||
yield obj[0] | yield obj[0] | ||||
▲ Show 20 Lines • Show All 1,057 Lines • Show Last 20 Lines |