Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/in_memory.py
Show First 20 Lines • Show All 286 Lines • ▼ Show 20 Lines | ) -> Dict[str, Any]: | ||||
"contents": matched, | "contents": matched, | ||||
"next": next_content, | "next": next_content, | ||||
} | } | ||||
def content_get_partition( | def content_get_partition( | ||||
self, | self, | ||||
partition_id: int, | partition_id: int, | ||||
nb_partitions: int, | nb_partitions: int, | ||||
limit: int = 1000, | |||||
page_token: Optional[str] = None, | page_token: Optional[str] = None, | ||||
) -> Dict[str, Any]: | limit: int = 1000, | ||||
) -> PagedResult[Content]: | |||||
if limit is None: | if limit is None: | ||||
raise StorageArgumentException("limit should not be None") | raise StorageArgumentException("limit should not be None") | ||||
(start, end) = get_partition_bounds_bytes( | (start, end) = get_partition_bounds_bytes( | ||||
partition_id, nb_partitions, SHA1_SIZE | partition_id, nb_partitions, SHA1_SIZE | ||||
) | ) | ||||
if page_token: | if page_token: | ||||
start = hash_to_bytes(page_token) | start = hash_to_bytes(page_token) | ||||
if end is None: | if end is None: | ||||
end = b"\xff" * SHA1_SIZE | end = b"\xff" * SHA1_SIZE | ||||
result = self.content_get_range(start, end, limit) | |||||
result2 = { | next_page_token: Optional[str] = None | ||||
"contents": result["contents"], | sha1s = ( | ||||
"next_page_token": None, | (sha1, content_key) | ||||
} | for sha1 in self._sorted_sha1s.iter_from(start) | ||||
if result["next"]: | for content_key in self._content_indexes["sha1"][sha1] | ||||
result2["next_page_token"] = hash_to_hex(result["next"]) | ) | ||||
return result2 | contents: List[Content] = [] | ||||
for counter, (sha1, key) in enumerate(sha1s): | |||||
if sha1 > end: | |||||
break | |||||
if counter >= limit: | |||||
next_page_token = hash_to_hex(sha1) | |||||
break | |||||
contents.append(self._contents[key]) | |||||
assert len(contents) <= limit | |||||
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 = {sha1: [] for sha1 in contents} | result: Dict = {sha1: [] for sha1 in contents} | ||||
for sha1 in contents: | for sha1 in contents: | ||||
if sha1 in self._content_indexes["sha1"]: | if sha1 in self._content_indexes["sha1"]: | ||||
objs = self._content_indexes["sha1"][sha1] | objs = self._content_indexes["sha1"][sha1] | ||||
# only 1 element as content_add_metadata would have raised a | # only 1 element as content_add_metadata would have raised a | ||||
# hash collision otherwise | # hash collision otherwise | ||||
▲ Show 20 Lines • Show All 982 Lines • Show Last 20 Lines |