Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/cassandra/storage.py
Show First 20 Lines • Show All 241 Lines • ▼ Show 20 Lines | def content_find(self, content: Dict[str, Any]) -> List[Content]: | ||||
break | break | ||||
else: | else: | ||||
# All hashes match, keep this row. | # All hashes match, keep this row. | ||||
row_d = row._asdict() | row_d = row._asdict() | ||||
row_d["ctime"] = row.ctime.replace(tzinfo=datetime.timezone.utc) | row_d["ctime"] = row.ctime.replace(tzinfo=datetime.timezone.utc) | ||||
results.append(Content(**row_d)) | results.append(Content(**row_d)) | ||||
return results | return results | ||||
def content_missing(self, content, key_hash="sha1"): | def content_missing( | ||||
for cont in content: | self, contents: List[Dict[str, Any]], key_hash: str = "sha1" | ||||
res = self.content_find(cont) | ) -> Iterable[bytes]: | ||||
if key_hash not in DEFAULT_ALGORITHMS: | |||||
raise StorageArgumentException( | |||||
"key_hash should be one of {','.join(DEFAULT_ALGORITHMS)}" | |||||
) | |||||
for content in contents: | |||||
res = self.content_find(content) | |||||
if not res: | if not res: | ||||
yield cont[key_hash] | yield content[key_hash] | ||||
def content_missing_per_sha1(self, contents): | def content_missing_per_sha1(self, contents): | ||||
return self.content_missing([{"sha1": c for c in contents}]) | return self.content_missing([{"sha1": c for c in contents}]) | ||||
def content_missing_per_sha1_git(self, contents): | def content_missing_per_sha1_git(self, contents): | ||||
return self.content_missing( | return self.content_missing( | ||||
[{"sha1_git": c for c in contents}], key_hash="sha1_git" | [{"sha1_git": c for c in contents}], key_hash="sha1_git" | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 966 Lines • Show Last 20 Lines |