Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/storage.py
Show First 20 Lines • Show All 1,490 Lines • ▼ Show 20 Lines | def origin_visit_get_latest( | ||||
associated to the visit | associated to the visit | ||||
""" | """ | ||||
origin_visit = db.origin_visit_get_latest( | origin_visit = db.origin_visit_get_latest( | ||||
origin, allowed_statuses=allowed_statuses, | origin, allowed_statuses=allowed_statuses, | ||||
require_snapshot=require_snapshot, cur=cur) | require_snapshot=require_snapshot, cur=cur) | ||||
if origin_visit: | if origin_visit: | ||||
return dict(zip(db.origin_visit_get_cols, origin_visit)) | return dict(zip(db.origin_visit_get_cols, origin_visit)) | ||||
@remote_api_endpoint('origin/visit/get_random') | |||||
@timed | |||||
@db_transaction() | |||||
def origin_visit_get_random( | |||||
ardumont: might as well add its str type now (which is missing). | |||||
self, type: str, db=None, cur=None) -> Mapping[str, Any]: | |||||
"""Randomly select one successful origin visit with <type> | |||||
made in the last 3 months. | |||||
Not Done Inline Actionsextra blank ardumont: extra blank | |||||
Returns: | |||||
dict representing an origin visit, in the same format as | |||||
:py:meth:`origin_visit_get`. | |||||
Not Done Inline Actionsfunc:origin_visit_get? ardumont: func:`origin_visit_get`? | |||||
Not Done Inline Actions(or whatever sphinx's docstring stanza to link to another method/function is) ardumont: (or whatever sphinx's docstring stanza to link to another method/function is) | |||||
""" | |||||
data: Dict[str, Any] = {} | |||||
result = db.origin_visit_get_random(type, cur) | |||||
if result: | |||||
data = dict(zip(db.origin_visit_get_cols, result)) | |||||
return data | |||||
@remote_api_endpoint('object/find_by_sha1_git') | @remote_api_endpoint('object/find_by_sha1_git') | ||||
@timed | @timed | ||||
@db_transaction(statement_timeout=2000) | @db_transaction(statement_timeout=2000) | ||||
def object_find_by_sha1_git(self, ids, db=None, cur=None): | def object_find_by_sha1_git(self, ids, db=None, cur=None): | ||||
"""Return the objects found with the given ids. | """Return the objects found with the given ids. | ||||
Args: | Args: | ||||
ids: a generator of sha1_gits | ids: a generator of sha1_gits | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | def origin_get_by_sha1(self, sha1s, db=None, cur=None): | ||||
""" | """ | ||||
for line in db.origin_get_by_sha1(sha1s, cur): | for line in db.origin_get_by_sha1(sha1s, cur): | ||||
if line[0] is not None: | if line[0] is not None: | ||||
yield dict(zip(db.origin_cols, line)) | yield dict(zip(db.origin_cols, line)) | ||||
else: | else: | ||||
yield None | yield None | ||||
@remote_api_endpoint('origin/visit/get_random') | |||||
@timed | |||||
@db_transaction() | |||||
def origin_visit_get_random( | |||||
self, type, db=None, cur=None) -> Mapping[str, Any]: | |||||
"""Randomly select one origin from the archive | |||||
Returns: | |||||
origin dict selected randomly on the dataset if found | |||||
""" | |||||
data: Dict[str, Any] = {} | |||||
result = db.origin_visit_get_random(type, cur) | |||||
if result: | |||||
data = dict(zip(db.origin_visit_get_cols, result)) | |||||
return data | |||||
@remote_api_endpoint('origin/get_range') | @remote_api_endpoint('origin/get_range') | ||||
@timed | @timed | ||||
@db_transaction_generator() | @db_transaction_generator() | ||||
def origin_get_range(self, origin_from=1, origin_count=100, | def origin_get_range(self, origin_from=1, origin_count=100, | ||||
db=None, cur=None): | db=None, cur=None): | ||||
"""Retrieve ``origin_count`` origins whose ids are greater | """Retrieve ``origin_count`` origins whose ids are greater | ||||
or equal than ``origin_from``. | or equal than ``origin_from``. | ||||
▲ Show 20 Lines • Show All 368 Lines • Show Last 20 Lines |
might as well add its str type now (which is missing).