Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/cassandra/storage.py
Show First 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | ) -> PagedResult[Content]: | ||||
# offset the range start according to the `page_token`. | # offset the range start according to the `page_token`. | ||||
if page_token is not None: | if page_token is not None: | ||||
if not (range_start <= int(page_token) <= range_end): | if not (range_start <= int(page_token) <= range_end): | ||||
raise StorageArgumentException("Invalid page_token.") | raise StorageArgumentException("Invalid page_token.") | ||||
range_start = int(page_token) | range_start = int(page_token) | ||||
next_page_token: Optional[str] = None | next_page_token: Optional[str] = None | ||||
rows = self._cql_runner.content_get_token_range(range_start, range_end, limit) | rows = self._cql_runner.content_get_token_range( | ||||
range_start, range_end, limit + 1 | |||||
) | |||||
contents = [] | contents = [] | ||||
last_id: Optional[int] = None | last_id: Optional[int] = None | ||||
for row in rows: | for counter, row in enumerate(rows): | ||||
if row.status == "absent": | if row.status == "absent": | ||||
continue | continue | ||||
row_d = row._asdict() | row_d = row._asdict() | ||||
last_id = row_d.pop("tok") | last_id = row_d.pop("tok") | ||||
if counter >= limit: | |||||
next_page_token = str(last_id) | |||||
break | |||||
contents.append(Content(**row_d)) | contents.append(Content(**row_d)) | ||||
if len(contents) == limit: | |||||
assert last_id is not None | |||||
next_page_token = str(last_id + 1) | |||||
assert len(contents) <= limit | assert len(contents) <= limit | ||||
return PagedResult(results=contents, next_page_token=next_page_token,) | return PagedResult(results=contents, next_page_token=next_page_token) | ||||
def content_get_metadata(self, contents: List[bytes]) -> Dict[bytes, List[Dict]]: | def content_get_metadata(self, contents: List[bytes]) -> 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 sha1 in contents: | for sha1 in contents: | ||||
# Get all (sha1, sha1_git, sha256, blake2s256) whose sha1 | # Get all (sha1, sha1_git, sha256, blake2s256) whose sha1 | ||||
# matches the argument, from the index table ('content_by_sha1') | # matches the argument, from the index table ('content_by_sha1') | ||||
for row in self._content_get_from_hash("sha1", sha1): | for row in self._content_get_from_hash("sha1", sha1): | ||||
content_metadata = row._asdict() | content_metadata = row._asdict() | ||||
▲ Show 20 Lines • Show All 1,049 Lines • Show Last 20 Lines |