Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/in_memory.py
Show First 20 Lines • Show All 288 Lines • ▼ Show 20 Lines | ) -> PagedResult[Content]: | ||||
if counter >= limit: | if counter >= limit: | ||||
next_page_token = hash_to_hex(sha1) | next_page_token = hash_to_hex(sha1) | ||||
break | break | ||||
contents.append(self._contents[key]) | contents.append(self._contents[key]) | ||||
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(self, contents: List[Sha1]) -> List[Optional[Content]]: | ||||
result: Dict = {sha1: [] for sha1 in contents} | contents_by_sha1: Dict[Sha1, Optional[Content]] = {} | ||||
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 | ||||
assert len(objs) == 1 | |||||
for key in objs: | for key in objs: | ||||
d = attr.evolve( | content = attr.evolve(self._contents[key], data=None, ctime=None) | ||||
self._contents[key], data=None, ctime=None | contents_by_sha1[sha1] = content | ||||
).to_dict() | return [contents_by_sha1.get(sha1) for sha1 in contents] | ||||
result[sha1].append(d) | |||||
return result | |||||
def content_find(self, content: Dict[str, Any]) -> List[Content]: | def content_find(self, content: Dict[str, Any]) -> List[Content]: | ||||
if not set(content).intersection(DEFAULT_ALGORITHMS): | if not set(content).intersection(DEFAULT_ALGORITHMS): | ||||
raise StorageArgumentException( | raise StorageArgumentException( | ||||
"content keys must contain at least one " | "content keys must contain at least one " | ||||
f"of: {', '.join(sorted(DEFAULT_ALGORITHMS))}" | f"of: {', '.join(sorted(DEFAULT_ALGORITHMS))}" | ||||
) | ) | ||||
found = [] | found = [] | ||||
▲ Show 20 Lines • Show All 967 Lines • Show Last 20 Lines |