Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/storage.py
Show First 20 Lines • Show All 918 Lines • ▼ Show 20 Lines | class Storage: | ||||
) -> Optional[OriginVisitStatus]: | ) -> Optional[OriginVisitStatus]: | ||||
row = db.origin_visit_status_get_latest( | row = db.origin_visit_status_get_latest( | ||||
origin_url, visit, allowed_statuses, require_snapshot, cur=cur | origin_url, visit, allowed_statuses, require_snapshot, cur=cur | ||||
) | ) | ||||
if not row: | if not row: | ||||
return None | return None | ||||
return OriginVisitStatus.from_dict(row) | return OriginVisitStatus.from_dict(row) | ||||
def _origin_visit_get_updated( | |||||
self, origin: str, visit_id: int, db, cur | |||||
) -> Optional[Dict[str, Any]]: | |||||
"""Retrieve origin visit and latest origin visit status and merge them | |||||
into an origin visit. | |||||
""" | |||||
row_visit = db.origin_visit_get(origin, visit_id) | |||||
if row_visit is None: | |||||
return None | |||||
visit = dict(zip(db.origin_visit_get_cols, row_visit)) | |||||
return self._origin_visit_apply_update(visit, db=db, cur=cur) | |||||
def _origin_visit_apply_update( | def _origin_visit_apply_update( | ||||
self, visit: Dict[str, Any], db, cur=None | self, visit: Dict[str, Any], db, cur=None | ||||
) -> Dict[str, Any]: | ) -> Dict[str, Any]: | ||||
"""Retrieve the latest visit status information for the origin visit. | """Retrieve the latest visit status information for the origin visit. | ||||
Then merge it with the visit and return it. | Then merge it with the visit and return it. | ||||
""" | """ | ||||
visit_status = db.origin_visit_status_get_latest( | visit_status = db.origin_visit_status_get_latest( | ||||
visit["origin"], visit["visit"], cur=cur | visit["origin"], visit["visit"], cur=cur | ||||
) | ) | ||||
return self._origin_visit_merge(visit, visit_status) | return { | ||||
def _origin_visit_merge( | |||||
self, visit: Dict[str, Any], visit_status: Dict[str, Any] | |||||
) -> Dict[str, Any]: | |||||
"""Merge origin_visit and origin_visit_status together. | |||||
""" | |||||
return OriginVisit.from_dict( | |||||
{ | |||||
# default to the values in visit | # default to the values in visit | ||||
**visit, | **visit, | ||||
# override with the last update | # override with the last update | ||||
**visit_status, | **visit_status, | ||||
# visit['origin'] is the URL (via a join), while | # visit['origin'] is the URL (via a join), while | ||||
# visit_status['origin'] is only an id. | # visit_status['origin'] is only an id. | ||||
"origin": visit["origin"], | "origin": visit["origin"], | ||||
# but keep the date of the creation of the origin visit | # but keep the date of the creation of the origin visit | ||||
"date": visit["date"], | "date": visit["date"], | ||||
} | } | ||||
).to_dict() | |||||
@timed | @timed | ||||
@db_transaction_generator(statement_timeout=500) | @db_transaction_generator(statement_timeout=500) | ||||
def origin_visit_get( | def origin_visit_get( | ||||
self, | self, | ||||
origin: str, | origin: str, | ||||
last_visit: Optional[int] = None, | last_visit: Optional[int] = None, | ||||
limit: Optional[int] = None, | limit: Optional[int] = None, | ||||
▲ Show 20 Lines • Show All 464 Lines • Show Last 20 Lines |