Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/postgresql/archive.py
# Copyright (C) 2021 The Software Heritage developers | # Copyright (C) 2021 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 General Public License version 3, or any later version | # License: GNU 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 | ||||
from typing import Any, Dict, Iterable, List | from typing import Any, Dict, Iterable, List | ||||
from methodtools import lru_cache | from methodtools import lru_cache | ||||
import psycopg2.extensions | import psycopg2.extensions | ||||
from swh.model.model import Sha1Git | from swh.model.model import Sha1Git | ||||
from swh.storage.postgresql.storage import Storage | from swh.storage import get_storage | ||||
class ArchivePostgreSQL: | class ArchivePostgreSQL: | ||||
def __init__(self, conn: psycopg2.extensions.connection) -> None: | def __init__(self, conn: psycopg2.extensions.connection) -> None: | ||||
self.storage = get_storage( | |||||
"postgresql", db=conn.dsn, objstorage={"cls": "memory"} | |||||
) | |||||
self.conn = conn | self.conn = conn | ||||
self.storage = Storage(conn, objstorage={"cls": "memory"}) | |||||
def directory_ls(self, id: Sha1Git) -> Iterable[Dict[str, Any]]: | def directory_ls(self, id: Sha1Git) -> Iterable[Dict[str, Any]]: | ||||
entries = self._directory_ls(id) | entries = self._directory_ls(id) | ||||
yield from entries | yield from entries | ||||
@lru_cache(maxsize=100000) | @lru_cache(maxsize=100000) | ||||
def _directory_ls(self, id: Sha1Git) -> List[Dict[str, Any]]: | def _directory_ls(self, id: Sha1Git) -> List[Dict[str, Any]]: | ||||
# TODO: add file size filtering | # TODO: add file size filtering | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |