Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/postgresql/archive.py
import psycopg2 | from typing import Any, Dict, List | ||||
# import threading | from methodtools import lru_cache | ||||
import psycopg2 | |||||
from ..archive import ArchiveInterface | from ..archive import ArchiveInterface | ||||
# from functools import lru_cache | |||||
from methodtools import lru_cache | |||||
from typing import Any, Dict, List | |||||
class ArchivePostgreSQL(ArchiveInterface): | class ArchivePostgreSQL(ArchiveInterface): | ||||
def __init__(self, conn: psycopg2.extensions.connection): | def __init__(self, conn: psycopg2.extensions.connection): | ||||
self.conn = conn | self.conn = conn | ||||
# self.mutex = threading.Lock() | |||||
def directory_ls(self, id: bytes) -> List[Dict[str, Any]]: | def directory_ls(self, id: bytes) -> List[Dict[str, Any]]: | ||||
# TODO: only call directory_ls_internal if the id is not being queried by | # TODO: only call directory_ls_internal if the id is not being queried by | ||||
# someone else. Otherwise wait until results get properly cached. | # someone else. Otherwise wait until results get properly cached. | ||||
# self.mutex.acquire() | |||||
entries = self.directory_ls_internal(id) | entries = self.directory_ls_internal(id) | ||||
# self.mutex.release() | |||||
return entries | return entries | ||||
@lru_cache(maxsize=1000000) | @lru_cache(maxsize=1000000) | ||||
def directory_ls_internal(self, id: bytes) -> List[Dict[str, Any]]: | def directory_ls_internal(self, id: bytes) -> List[Dict[str, Any]]: | ||||
# TODO: add file size filtering | # TODO: add file size filtering | ||||
cursor = self.conn.cursor() | cursor = self.conn.cursor() | ||||
cursor.execute( | cursor.execute( | ||||
"""WITH | """WITH | ||||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |