Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/snapshot_context.py
# Copyright (C) 2018-2020 The Software Heritage developers | # Copyright (C) 2018-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
# Utility module for browsing the archive in a snapshot context. | # Utility module for browsing the archive in a snapshot context. | ||||
from collections import defaultdict | from collections import defaultdict | ||||
from copy import copy | from copy import copy | ||||
from typing import Any, Dict, List, Optional, Union, Tuple | from typing import Any, Dict, List, Optional, Tuple | ||||
from django.core.cache import cache | from django.core.cache import cache | ||||
from django.shortcuts import render | from django.shortcuts import render | ||||
from django.template.defaultfilters import filesizeformat | from django.template.defaultfilters import filesizeformat | ||||
from django.utils.html import escape | from django.utils.html import escape | ||||
import sentry_sdk | import sentry_sdk | ||||
▲ Show 20 Lines • Show All 324 Lines • ▼ Show 20 Lines | ) -> Tuple[List[SnapshotBranchInfo], List[SnapshotReleaseInfo]]: | ||||
cache.set(cache_entry_id, {"branches": branches, "releases": releases,}) | cache.set(cache_entry_id, {"branches": branches, "releases": releases,}) | ||||
return branches, releases | return branches, releases | ||||
def get_origin_visit_snapshot( | def get_origin_visit_snapshot( | ||||
origin_info: OriginInfo, | origin_info: OriginInfo, | ||||
visit_ts: Optional[Union[int, str]] = None, | visit_ts: Optional[str] = None, | ||||
visit_id: Optional[int] = None, | visit_id: Optional[int] = None, | ||||
snapshot_id: Optional[str] = None, | snapshot_id: Optional[str] = None, | ||||
) -> Tuple[List[SnapshotBranchInfo], List[SnapshotReleaseInfo]]: | ) -> Tuple[List[SnapshotBranchInfo], List[SnapshotReleaseInfo]]: | ||||
"""Returns the lists of branches and releases associated to an origin for | """Returns the lists of branches and releases associated to an origin for | ||||
a given visit. | a given visit. | ||||
The visit is expressed by either: | The visit is expressed by either: | ||||
* a snapshot identifier | * a snapshot identifier | ||||
* a timestamp, if no visit with that exact timestamp is found, | * a timestamp, if no visit with that exact timestamp is found, | ||||
the closest one from the provided timestamp will be used. | the closest one from the provided timestamp will be used. | ||||
If no visit parameter is provided, it returns the list of branches | If no visit parameter is provided, it returns the list of branches | ||||
found for the latest visit. | found for the latest visit. | ||||
That list is put in cache in order to speedup the navigation | That list is put in cache in order to speedup the navigation | ||||
in the swh-web/browse ui. | in the swh-web/browse ui. | ||||
.. warning:: At most 1000 branches contained in the snapshot | .. warning:: At most 1000 branches contained in the snapshot | ||||
will be returned for performance reasons. | will be returned for performance reasons. | ||||
Args: | Args: | ||||
origin_info: a dict filled with origin information | origin_info: a dict filled with origin information | ||||
visit_ts: an ISO date string or Unix timestamp to parse | visit_ts: an ISO 8601 datetime string to parse | ||||
visit_id: visit id for disambiguation in case several visits have | visit_id: visit id for disambiguation in case several visits have | ||||
the same timestamp | the same timestamp | ||||
snapshot_id: if provided, visit associated to the snapshot will be processed | snapshot_id: if provided, visit associated to the snapshot will be processed | ||||
Returns: | Returns: | ||||
A tuple with two members. The first one is a list of dict describing | A tuple with two members. The first one is a list of dict describing | ||||
the origin branches for the given visit. | the origin branches for the given visit. | ||||
The second one is a list of dict describing the origin releases | The second one is a list of dict describing the origin releases | ||||
▲ Show 20 Lines • Show All 1,082 Lines • Show Last 20 Lines |