Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/in_memory.py
Show First 20 Lines • Show All 348 Lines • ▼ Show 20 Lines | class Storage: | ||||
def content_get_metadata(self, content): | def content_get_metadata(self, content): | ||||
"""Retrieve content metadata in bulk | """Retrieve content metadata in bulk | ||||
Args: | Args: | ||||
content: iterable of content identifiers (sha1) | content: iterable of content identifiers (sha1) | ||||
Returns: | Returns: | ||||
an iterable with content metadata corresponding to the given ids | an iterable with content metadata corresponding to the given | ||||
ids | |||||
""" | """ | ||||
# FIXME: the return value should be a mapping from search key to found | # FIXME: the return value should be a mapping from search key to found | ||||
# content*s* | # content*s* | ||||
for sha1 in content: | for sha1 in content: | ||||
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] | ||||
# FIXME: rather than selecting one of the objects with that | # FIXME: rather than selecting one of the objects with that | ||||
# hash, we should return all of them. See: | # hash, we should return all of them. See: | ||||
# https://forge.softwareheritage.org/D645?id=1994#inline-3389 | # https://forge.softwareheritage.org/D645?id=1994#inline-3389 | ||||
ardumont: This can actually be fixed in that diff now as @vlorentz mentioned.
In progress ;) | |||||
key = random.sample(objs, 1)[0] | key = random.sample(objs, 1)[0] | ||||
d = self._contents[key].to_dict() | d = self._contents[key].to_dict() | ||||
del d['ctime'] | del d['ctime'] | ||||
yield d | yield d | ||||
else: | else: | ||||
# FIXME: should really be None | continue | ||||
Done Inline ActionsIs it better to skip it or to yield None here? ardumont: Is it better to skip it or to `yield None` here? | |||||
yield { | |||||
'sha1': sha1, | |||||
'sha1_git': None, | |||||
'sha256': None, | |||||
'blake2s256': None, | |||||
'length': None, | |||||
'status': None, | |||||
} | |||||
def content_find(self, content): | def content_find(self, content): | ||||
if not set(content).intersection(DEFAULT_ALGORITHMS): | if not set(content).intersection(DEFAULT_ALGORITHMS): | ||||
raise ValueError('content keys must contain at least one of: ' | raise ValueError('content keys must contain at least one of: ' | ||||
'%s' % ', '.join(sorted(DEFAULT_ALGORITHMS))) | '%s' % ', '.join(sorted(DEFAULT_ALGORITHMS))) | ||||
found = [] | found = [] | ||||
for algo in DEFAULT_ALGORITHMS: | for algo in DEFAULT_ALGORITHMS: | ||||
hash = content.get(algo) | hash = content.get(algo) | ||||
▲ Show 20 Lines • Show All 1,467 Lines • Show Last 20 Lines |
This can actually be fixed in that diff now as @vlorentz mentioned.
In progress ;)