Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/in_memory.py
Show First 20 Lines • Show All 257 Lines • ▼ Show 20 Lines | class InMemoryStorage: | ||||
) -> Iterable[Optional[Dict[str, bytes]]]: | ) -> Iterable[Optional[Dict[str, bytes]]]: | ||||
# FIXME: Make this method support slicing the `data`. | # FIXME: Make this method support slicing the `data`. | ||||
if len(contents) > BULK_BLOCK_CONTENT_LEN_MAX: | if len(contents) > BULK_BLOCK_CONTENT_LEN_MAX: | ||||
raise StorageArgumentException( | raise StorageArgumentException( | ||||
f"Send at maximum {BULK_BLOCK_CONTENT_LEN_MAX} contents." | f"Send at maximum {BULK_BLOCK_CONTENT_LEN_MAX} contents." | ||||
) | ) | ||||
yield from self.objstorage.content_get(contents) | yield from self.objstorage.content_get(contents) | ||||
def content_get_range(self, start, end, limit=1000): | def content_get_range( | ||||
self, start: bytes, end: bytes, limit: int = 1000 | |||||
) -> Dict[str, Any]: | |||||
if limit is None: | if limit is None: | ||||
raise StorageArgumentException("limit should not be None") | raise StorageArgumentException("limit should not be None") | ||||
sha1s = ( | sha1s = ( | ||||
(sha1, content_key) | (sha1, content_key) | ||||
for sha1 in self._sorted_sha1s.iter_from(start) | for sha1 in self._sorted_sha1s.iter_from(start) | ||||
for content_key in self._content_indexes["sha1"][sha1] | for content_key in self._content_indexes["sha1"][sha1] | ||||
) | ) | ||||
matched = [] | matched: List[Dict[str, Any]] = [] | ||||
next_content = None | next_content = None | ||||
for sha1, key in sha1s: | for sha1, key in sha1s: | ||||
if sha1 > end: | if sha1 > end: | ||||
break | break | ||||
if len(matched) >= limit: | if len(matched) >= limit: | ||||
next_content = sha1 | next_content = sha1 | ||||
break | break | ||||
matched.append(self._contents[key].to_dict()) | matched.append(self._contents[key].to_dict()) | ||||
▲ Show 20 Lines • Show All 988 Lines • Show Last 20 Lines |