Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/backfill.py
Show All 10 Lines | |||||
Current implementation consists in the JournalBackfiller class. | Current implementation consists in the JournalBackfiller class. | ||||
It simply reads the objects from the storage and sends every object identifier back to | It simply reads the objects from the storage and sends every object identifier back to | ||||
the journal. | the journal. | ||||
""" | """ | ||||
import logging | import logging | ||||
from typing import Any, Callable, Dict | from typing import Any, Callable, Dict, Optional | ||||
from swh.core.db import BaseDb | from swh.core.db import BaseDb | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
BaseModel, | BaseModel, | ||||
Directory, | Directory, | ||||
DirectoryEntry, | DirectoryEntry, | ||||
RawExtrinsicMetadata, | RawExtrinsicMetadata, | ||||
Release, | Release, | ||||
▲ Show 20 Lines • Show All 223 Lines • ▼ Show 20 Lines | def snapshot_converter(db: BaseDb, snapshot_d: Dict[str, Any]) -> Snapshot: | ||||
""" % ", ".join( | """ % ", ".join( | ||||
columns | columns | ||||
) | ) | ||||
with db.cursor() as cur: | with db.cursor() as cur: | ||||
cur.execute(query, (snapshot_d["object_id"],)) | cur.execute(query, (snapshot_d["object_id"],)) | ||||
branches = {} | branches = {} | ||||
for name, *row in cur: | for name, *row in cur: | ||||
branch_d = dict(zip(columns[1:], row)) | branch_d = dict(zip(columns[1:], row)) | ||||
if branch_d["target"] or branch_d["target_type"]: | if branch_d["target"] is not None and branch_d["target_type"] is not None: | ||||
branch = None | branch: Optional[SnapshotBranch] = SnapshotBranch( | ||||
else: | |||||
branch = SnapshotBranch( | |||||
target=branch_d["target"], | target=branch_d["target"], | ||||
target_type=TargetType(branch_d["target_type"]), | target_type=TargetType(branch_d["target_type"]), | ||||
) | ) | ||||
else: | |||||
branch = None | |||||
branches[name] = branch | branches[name] = branch | ||||
return Snapshot(id=snapshot_d["id"], branches=branches,) | return Snapshot(id=snapshot_d["id"], branches=branches,) | ||||
CONVERTERS: Dict[str, Callable[[BaseDb, Dict[str, Any]], BaseModel]] = { | CONVERTERS: Dict[str, Callable[[BaseDb, Dict[str, Any]], BaseModel]] = { | ||||
"directory": directory_converter, | "directory": directory_converter, | ||||
"raw_extrinsic_metadata": raw_extrinsic_metadata_converter, | "raw_extrinsic_metadata": raw_extrinsic_metadata_converter, | ||||
▲ Show 20 Lines • Show All 281 Lines • Show Last 20 Lines |