Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/storage/archive.py
Show All 12 Lines | |||||
ARCHIVE_DURATION_METRIC = "swh_provenance_archive_api_duration_seconds" | ARCHIVE_DURATION_METRIC = "swh_provenance_archive_api_duration_seconds" | ||||
class ArchiveStorage: | class ArchiveStorage: | ||||
def __init__(self, storage: StorageInterface) -> None: | def __init__(self, storage: StorageInterface) -> None: | ||||
self.storage = storage | self.storage = storage | ||||
@statsd.timed(metric=ARCHIVE_DURATION_METRIC, tags={"method": "directory_ls"}) | @statsd.timed(metric=ARCHIVE_DURATION_METRIC, tags={"method": "directory_ls"}) | ||||
def directory_ls(self, id: Sha1Git) -> Iterable[Dict[str, Any]]: | def directory_ls(self, id: Sha1Git, minsize: int = 0) -> Iterable[Dict[str, Any]]: | ||||
# TODO: add file size filtering | |||||
for entry in self.storage.directory_ls(id): | for entry in self.storage.directory_ls(id): | ||||
if entry["type"] == "dir" or ( | |||||
entry["type"] == "file" and entry["length"] >= minsize | |||||
): | |||||
yield { | yield { | ||||
"name": entry["name"], | "name": entry["name"], | ||||
"target": entry["target"], | "target": entry["target"], | ||||
"type": entry["type"], | "type": entry["type"], | ||||
} | } | ||||
@statsd.timed( | @statsd.timed( | ||||
metric=ARCHIVE_DURATION_METRIC, tags={"method": "revision_get_parents"} | metric=ARCHIVE_DURATION_METRIC, tags={"method": "revision_get_parents"} | ||||
) | ) | ||||
def revision_get_parents(self, id: Sha1Git) -> Iterable[Sha1Git]: | def revision_get_parents(self, id: Sha1Git) -> Iterable[Sha1Git]: | ||||
rev = self.storage.revision_get([id])[0] | rev = self.storage.revision_get([id])[0] | ||||
if rev is not None: | if rev is not None: | ||||
yield from rev.parents | yield from rev.parents | ||||
Show All 35 Lines |