diff --git a/swh/storage/cassandra/storage.py b/swh/storage/cassandra/storage.py --- a/swh/storage/cassandra/storage.py +++ b/swh/storage/cassandra/storage.py @@ -163,12 +163,15 @@ def content_add_metadata(self, content: List[Content]) -> Dict: return self._content_add(content, with_data=False) - def content_get(self, content): - if len(content) > BULK_BLOCK_CONTENT_LEN_MAX: + def content_get( + self, contents: List[bytes] + ) -> Iterable[Optional[Dict[str, bytes]]]: + # FIXME: Make this method support slicing the `data`. + if len(contents) > BULK_BLOCK_CONTENT_LEN_MAX: raise StorageArgumentException( - "Sending at most %s contents." % BULK_BLOCK_CONTENT_LEN_MAX + f"Send at maximum {BULK_BLOCK_CONTENT_LEN_MAX} contents." ) - yield from self.objstorage.content_get(content) + yield from self.objstorage.content_get(contents) def content_get_partition( self, diff --git a/swh/storage/in_memory.py b/swh/storage/in_memory.py --- a/swh/storage/in_memory.py +++ b/swh/storage/in_memory.py @@ -251,13 +251,15 @@ def content_add_metadata(self, content: List[Content]) -> Dict: return self._content_add(content, with_data=False) - def content_get(self, content): + def content_get( + self, contents: List[bytes] + ) -> Iterable[Optional[Dict[str, bytes]]]: # FIXME: Make this method support slicing the `data`. - if len(content) > BULK_BLOCK_CONTENT_LEN_MAX: + if len(contents) > BULK_BLOCK_CONTENT_LEN_MAX: raise StorageArgumentException( - "Sending at most %s contents." % BULK_BLOCK_CONTENT_LEN_MAX + f"Send at maximum {BULK_BLOCK_CONTENT_LEN_MAX} contents." ) - yield from self.objstorage.content_get(content) + yield from self.objstorage.content_get(contents) def content_get_range(self, start, end, limit=1000): if limit is None: diff --git a/swh/storage/interface.py b/swh/storage/interface.py --- a/swh/storage/interface.py +++ b/swh/storage/interface.py @@ -146,7 +146,9 @@ ... @remote_api_endpoint("content/data") - def content_get(self, content): + def content_get( + self, contents: List[bytes] + ) -> Iterable[Optional[Dict[str, bytes]]]: """Retrieve in bulk contents and their data. This generator yields exactly as many items than provided sha1 @@ -154,20 +156,22 @@ It may also yield `None` values in case an object was not found. + TODO: + Rename to content_get_data + Args: - content: iterables of sha1 + contents: iterables of sha1 + + Raises: + StorageArgumentException in case of too much contents are required. + (cf. BULK_BLOCK_CONTENT_LEN_MAX) Yields: - Dict[str, bytes]: Generates streams of contents as dict with their - raw data: + Streams of contents as dict with their raw data: - sha1 (bytes): content id - data (bytes): content's raw data - Raises: - ValueError in case of too much contents are required. - cf. BULK_BLOCK_CONTENT_LEN_MAX - """ ... diff --git a/swh/storage/storage.py b/swh/storage/storage.py --- a/swh/storage/storage.py +++ b/swh/storage/storage.py @@ -266,13 +266,15 @@ } @timed - def content_get(self, content): + def content_get( + self, contents: List[bytes] + ) -> Iterable[Optional[Dict[str, bytes]]]: # FIXME: Make this method support slicing the `data`. - if len(content) > BULK_BLOCK_CONTENT_LEN_MAX: + if len(contents) > BULK_BLOCK_CONTENT_LEN_MAX: raise StorageArgumentException( - "Send at maximum %s contents." % BULK_BLOCK_CONTENT_LEN_MAX + f"Send at maximum {BULK_BLOCK_CONTENT_LEN_MAX} contents." ) - yield from self.objstorage.content_get(content) + yield from self.objstorage.content_get(contents) @timed @db_transaction()