Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/storage.py
Show First 20 Lines • Show All 328 Lines • ▼ Show 20 Lines | def content_add_metadata(self, content): | ||||
self._filter_new_content(content) | self._filter_new_content(content) | ||||
with db.transaction() as cur: | with db.transaction() as cur: | ||||
self._content_add_metadata( | self._content_add_metadata( | ||||
db, cur, content_with_data, content_without_data) | db, cur, content_with_data, content_without_data) | ||||
return summary | return summary | ||||
def content_get(self, content): | def content_get(self, content, start=0, end=-1): | ||||
"""Retrieve in bulk contents and their data. | """Retrieve in bulk contents and their data. | ||||
This generator yields exactly as many items than provided sha1 | This generator yields exactly as many items than provided sha1 | ||||
identifiers, but callers should not assume this will always be true. | identifiers, but callers should not assume this will always be true. | ||||
It may also yield `None` values in case an object was not found. | It may also yield `None` values in case an object was not found. | ||||
Args: | Args: | ||||
Show All 18 Lines | def content_get(self, content, start=0, end=-1): | ||||
for obj_id in content: | for obj_id in content: | ||||
try: | try: | ||||
data = self.objstorage.get(obj_id) | data = self.objstorage.get(obj_id) | ||||
except ObjNotFoundError: | except ObjNotFoundError: | ||||
yield None | yield None | ||||
continue | continue | ||||
if end != -1: | |||||
yield {'sha1': obj_id, 'data': data[start:end]} | |||||
else: | |||||
yield {'sha1': obj_id, 'data': data} | yield {'sha1': obj_id, 'data': data} | ||||
@db_transaction() | @db_transaction() | ||||
def content_get_range(self, start, end, limit=1000, db=None, cur=None): | def content_get_range(self, start, end, limit=1000, db=None, cur=None): | ||||
"""Retrieve contents within range [start, end] bound by limit. | """Retrieve contents within range [start, end] bound by limit. | ||||
Note that this function may return more than one blob per hash. The | Note that this function may return more than one blob per hash. The | ||||
limit is enforced with multiplicity (ie. two blobs with the same hash | limit is enforced with multiplicity (ie. two blobs with the same hash | ||||
will count twice toward the limit). | will count twice toward the limit). | ||||
▲ Show 20 Lines • Show All 1,423 Lines • Show Last 20 Lines |