Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/origin_visits.py
Show First 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | if visit_id: | ||||
( | ( | ||||
"Visit with id %s for origin with" | "Visit with id %s for origin with" | ||||
" url %s not found!" % (visit_id, origin_info["url"]) | " url %s not found!" % (visit_id, origin_info["url"]) | ||||
) | ) | ||||
) | ) | ||||
return visits[0] | return visits[0] | ||||
if not visit_ts: | if not visit_ts: | ||||
# returns the latest visit with a valid snapshot when no timestamp is provided | # returns the latest full visit with a valid snapshot or | ||||
for v in reversed(visits): | # the latest partial visit with a valid snapshot otherwise | ||||
for status in ("full", "partial"): | |||||
visits_filtered = [v for v in visits if v["status"] == status] | |||||
for v in reversed(visits_filtered): | |||||
if v["snapshot"] is not None: | if v["snapshot"] is not None: | ||||
return v | return v | ||||
ardumont: Having the snapshot-id set does not mean that it's necessarily valid currently (unfortunately)… | |||||
return visits[-1] | return visits[-1] | ||||
target_visit_ts = math.floor(parse_timestamp(visit_ts).timestamp()) | target_visit_ts = math.floor(parse_timestamp(visit_ts).timestamp()) | ||||
# Find the visit with date closest to the target (in absolute value) | # Find the visit with date closest to the target (in absolute value) | ||||
(abs_time_delta, visit_idx) = min( | (abs_time_delta, visit_idx) = min( | ||||
( | ( | ||||
(math.floor(parse_timestamp(visit["date"]).timestamp()), i) | (math.floor(parse_timestamp(visit["date"]).timestamp()), i) | ||||
Show All 23 Lines |
Having the snapshot-id set does not mean that it's necessarily valid currently (unfortunately) [1]
[1] D3322