Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/storage.py
Show All 39 Lines | from swh.model.model import ( | ||||
SHA1_SIZE, | SHA1_SIZE, | ||||
MetadataAuthority, | MetadataAuthority, | ||||
MetadataAuthorityType, | MetadataAuthorityType, | ||||
MetadataFetcher, | MetadataFetcher, | ||||
MetadataTargetType, | MetadataTargetType, | ||||
RawExtrinsicMetadata, | RawExtrinsicMetadata, | ||||
) | ) | ||||
from swh.model.hashutil import DEFAULT_ALGORITHMS, hash_to_bytes, hash_to_hex | from swh.model.hashutil import DEFAULT_ALGORITHMS, hash_to_bytes, hash_to_hex | ||||
from swh.storage.interface import ListOrder, PagedResult | from swh.storage.interface import ListOrder, PagedResult, VISIT_STATUSES | ||||
from swh.storage.objstorage import ObjStorage | from swh.storage.objstorage import ObjStorage | ||||
from swh.storage.utils import now | from swh.storage.utils import now | ||||
from . import converters | from . import converters | ||||
from .common import db_transaction_generator, db_transaction | from .common import db_transaction_generator, db_transaction | ||||
from .db import Db | from .db import Db | ||||
from .exc import StorageArgumentException, StorageDBError, HashCollision | from .exc import StorageArgumentException, StorageDBError, HashCollision | ||||
from .algos import diff | from .algos import diff | ||||
▲ Show 20 Lines • Show All 800 Lines • ▼ Show 20 Lines | def origin_visit_status_get_latest( | ||||
self, | self, | ||||
origin_url: str, | origin_url: str, | ||||
visit: int, | visit: int, | ||||
allowed_statuses: Optional[List[str]] = None, | allowed_statuses: Optional[List[str]] = None, | ||||
require_snapshot: bool = False, | require_snapshot: bool = False, | ||||
db=None, | db=None, | ||||
cur=None, | cur=None, | ||||
) -> Optional[OriginVisitStatus]: | ) -> Optional[OriginVisitStatus]: | ||||
if allowed_statuses and not set(allowed_statuses).intersection(VISIT_STATUSES): | |||||
raise StorageArgumentException( | |||||
f"Unknown allowed statuses {','.join(allowed_statuses)}, only " | |||||
f"{','.join(VISIT_STATUSES)} authorized" | |||||
) | |||||
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) | ||||
@timed | @timed | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | def origin_visit_get_latest( | ||||
self, | self, | ||||
origin: str, | origin: str, | ||||
type: Optional[str] = None, | type: Optional[str] = None, | ||||
allowed_statuses: Optional[List[str]] = None, | allowed_statuses: Optional[List[str]] = None, | ||||
require_snapshot: bool = False, | require_snapshot: bool = False, | ||||
db=None, | db=None, | ||||
cur=None, | cur=None, | ||||
) -> Optional[OriginVisit]: | ) -> Optional[OriginVisit]: | ||||
if allowed_statuses and not set(allowed_statuses).intersection(VISIT_STATUSES): | |||||
raise StorageArgumentException( | |||||
f"Unknown allowed statuses {','.join(allowed_statuses)}, only " | |||||
f"{','.join(VISIT_STATUSES)} authorized" | |||||
) | |||||
row = db.origin_visit_get_latest( | row = db.origin_visit_get_latest( | ||||
origin, | origin, | ||||
type=type, | type=type, | ||||
allowed_statuses=allowed_statuses, | allowed_statuses=allowed_statuses, | ||||
require_snapshot=require_snapshot, | require_snapshot=require_snapshot, | ||||
cur=cur, | cur=cur, | ||||
) | ) | ||||
if row: | if row: | ||||
▲ Show 20 Lines • Show All 428 Lines • Show Last 20 Lines |