Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/algos/origin.py
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | Args: | ||||
have successfully run to completion. | have successfully run to completion. | ||||
require_snapshot: If True, only a visit with a snapshot | require_snapshot: If True, only a visit with a snapshot | ||||
will be returned. | will be returned. | ||||
Returns: | Returns: | ||||
a tuple of (visit, visit_status) model object if the visit *and* the visit | a tuple of (visit, visit_status) model object if the visit *and* the visit | ||||
status exist (and match the search criteria), None otherwise. | status exist (and match the search criteria), None otherwise. | ||||
""" | """ | ||||
# visits order are from older visit to most recent. | last_visit = None | ||||
ardumont: oh, no longer need to `list` it... ;) | |||||
Done Inline Actionswrong, need it for the no result case. ardumont: wrong, need it for the no result case. | |||||
visits = list(storage.origin_visit_get(origin_url)) | while True: | ||||
visits.reverse() | visits = list( | ||||
storage.origin_visit_get( | |||||
origin_url, last_visit=last_visit, order="desc", limit=10, | |||||
) | |||||
) | |||||
if not visits: | if not visits: | ||||
return None | return None | ||||
last_visit = visits[-1]["visit"] | |||||
visit_status: Optional[OriginVisitStatus] = None | visit_status: Optional[OriginVisitStatus] = None | ||||
visit: Dict[str, Any] | visit: Dict[str, Any] | ||||
# Iterate over the visits in reverse order, so the most recent match is found first | |||||
for visit in visits: | for visit in visits: | ||||
if type is not None and visit["type"] != type: | if type is not None and visit["type"] != type: | ||||
continue | continue | ||||
visit_status = storage.origin_visit_status_get_latest( | visit_status = storage.origin_visit_status_get_latest( | ||||
origin_url, | origin_url, | ||||
visit["visit"], | visit["visit"], | ||||
allowed_statuses=allowed_statuses, | allowed_statuses=allowed_statuses, | ||||
require_snapshot=require_snapshot, | require_snapshot=require_snapshot, | ||||
) | ) | ||||
if visit_status is not None: | if visit_status is not None: | ||||
break | |||||
if visit_status is None: | |||||
return None | |||||
return (OriginVisit.from_dict(visit), visit_status) | return (OriginVisit.from_dict(visit), visit_status) | ||||
Done Inline ActionsThis is not needed, we'll get out of the loop with line 79. ardumont: This is not needed, we'll get out of the loop with line 79. |
oh, no longer need to list it... ;)