Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/storage.py
Show First 20 Lines • Show All 1,043 Lines • ▼ Show 20 Lines | def snapshot_get_latest(self, origin, allowed_statuses=None, db=None, | ||||
order of their names. | order of their names. | ||||
.. warning:: At most 1000 branches contained in the snapshot will be | .. warning:: At most 1000 branches contained in the snapshot will be | ||||
returned for performance reasons. In order to browse the whole | returned for performance reasons. In order to browse the whole | ||||
set of branches, the method :meth:`snapshot_get_branches` | set of branches, the method :meth:`snapshot_get_branches` | ||||
should be used instead. | should be used instead. | ||||
Args: | Args: | ||||
origin (int): the origin identifier | origin (Union[str,int]): the origin's URL or identifier | ||||
allowed_statuses (list of str): list of visit statuses considered | allowed_statuses (list of str): list of visit statuses considered | ||||
to find the latest snapshot for the visit. For instance, | to find the latest snapshot for the visit. For instance, | ||||
``allowed_statuses=['full']`` will only consider visits that | ``allowed_statuses=['full']`` will only consider visits that | ||||
have successfully run to completion. | have successfully run to completion. | ||||
Returns: | Returns: | ||||
dict: a dict with three keys: | dict: a dict with three keys: | ||||
* **id**: identifier of the snapshot | * **id**: identifier of the snapshot | ||||
* **branches**: a dict of branches contained in the snapshot | * **branches**: a dict of branches contained in the snapshot | ||||
whose keys are the branches' names. | whose keys are the branches' names. | ||||
* **next_branch**: the name of the first branch not returned | * **next_branch**: the name of the first branch not returned | ||||
or :const:`None` if the snapshot has less than 1000 | or :const:`None` if the snapshot has less than 1000 | ||||
branches. | branches. | ||||
""" | """ | ||||
if isinstance(origin, str): | |||||
origin = self.origin_get({'url': origin})['id'] | |||||
ardumont: cur=cur, db=db! | |||||
origin_visit = db.origin_visit_get_latest_snapshot( | origin_visit = db.origin_visit_get_latest_snapshot( | ||||
origin, allowed_statuses=allowed_statuses, cur=cur) | origin, allowed_statuses=allowed_statuses, cur=cur) | ||||
if origin_visit: | if origin_visit: | ||||
origin_visit = dict(zip(db.origin_visit_get_cols, origin_visit)) | origin_visit = dict(zip(db.origin_visit_get_cols, origin_visit)) | ||||
return self.snapshot_get(origin_visit['snapshot'], db=db, cur=cur) | return self.snapshot_get(origin_visit['snapshot'], db=db, cur=cur) | ||||
@db_transaction(statement_timeout=2000) | @db_transaction(statement_timeout=2000) | ||||
def snapshot_count_branches(self, snapshot_id, db=None, cur=None): | def snapshot_count_branches(self, snapshot_id, db=None, cur=None): | ||||
▲ Show 20 Lines • Show All 741 Lines • Show Last 20 Lines |
cur=cur, db=db!