Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/cassandra/storage.py
Show First 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | def check_config(self, *, check_write: bool) -> bool: | ||||
return True | return True | ||||
def _content_get_from_hashes(self, algo, hashes: List[bytes]) -> Iterable: | def _content_get_from_hashes(self, algo, hashes: List[bytes]) -> Iterable: | ||||
"""From the name of a hash algorithm and a value of that hash, | """From the name of a hash algorithm and a value of that hash, | ||||
looks up the "hash -> token" secondary table (content_by_{algo}) | looks up the "hash -> token" secondary table (content_by_{algo}) | ||||
to get tokens. | to get tokens. | ||||
Then, looks up the main table (content) to get all contents with | Then, looks up the main table (content) to get all contents with | ||||
that token, and filters out contents whose hash doesn't match.""" | that token, and filters out contents whose hash doesn't match.""" | ||||
found_tokens = self._cql_runner.content_get_tokens_from_single_algo( | found_tokens = list( | ||||
algo, hashes | self._cql_runner.content_get_tokens_from_single_algo(algo, hashes) | ||||
) | ) | ||||
assert all(isinstance(token, int) for token in found_tokens) | |||||
for token in found_tokens: | |||||
assert isinstance(token, int), found_tokens | |||||
# Query the main table ('content'). | # Query the main table ('content'). | ||||
res = self._cql_runner.content_get_from_token(token) | rows = self._cql_runner.content_get_from_tokens(found_tokens) | ||||
for row in rows: | |||||
for row in res: | |||||
# re-check the the hash (in case of murmur3 collision) | # re-check the the hash (in case of murmur3 collision) | ||||
if getattr(row, algo) in hashes: | if getattr(row, algo) in hashes: | ||||
yield row | yield row | ||||
def _content_add(self, contents: List[Content], with_data: bool) -> Dict[str, int]: | def _content_add(self, contents: List[Content], with_data: bool) -> Dict[str, int]: | ||||
# Filter-out content already in the database. | # Filter-out content already in the database. | ||||
if not self._allow_overwrite: | if not self._allow_overwrite: | ||||
contents = [ | contents = [ | ||||
c | c | ||||
for c in contents | for c in contents | ||||
if not self._cql_runner.content_get_from_pk(c.to_dict()) | if not self._cql_runner.content_get_from_pk(c.to_dict()) | ||||
▲ Show 20 Lines • Show All 1,521 Lines • Show Last 20 Lines |