Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/postgresql/storage.py
Show First 20 Lines • Show All 686 Lines • ▼ Show 20 Lines | class Storage: | ||||
@timed | @timed | ||||
@db_transaction() | @db_transaction() | ||||
def revision_get_random(self, *, db: Db, cur=None) -> Sha1Git: | def revision_get_random(self, *, db: Db, cur=None) -> Sha1Git: | ||||
return db.revision_get_random(cur) | return db.revision_get_random(cur) | ||||
@timed | @timed | ||||
@db_transaction() | @db_transaction() | ||||
def extid_get_from_extid( | def extid_get_from_extid( | ||||
self, id_type: str, ids: List[bytes], *, db: Db, cur=None | self, | ||||
id_type: str, | |||||
ids: List[bytes], | |||||
version: Optional[int] = None, | |||||
*, | |||||
db: Db, | |||||
cur=None, | |||||
) -> List[ExtID]: | ) -> List[ExtID]: | ||||
extids = [] | extids = [] | ||||
for row in db.extid_get_from_extid_list(id_type, ids, cur): | for row in db.extid_get_from_extid_list(id_type, ids, version=version, cur=cur): | ||||
if row[0] is not None: | if row[0] is not None: | ||||
extids.append(converters.db_to_extid(dict(zip(db.extid_cols, row)))) | extids.append(converters.db_to_extid(dict(zip(db.extid_cols, row)))) | ||||
return extids | return extids | ||||
@timed | @timed | ||||
@db_transaction() | @db_transaction() | ||||
def extid_get_from_target( | def extid_get_from_target( | ||||
self, target_type: ObjectType, ids: List[Sha1Git], *, db: Db, cur=None | self, | ||||
target_type: ObjectType, | |||||
ids: List[Sha1Git], | |||||
extid_type: Optional[str] = None, | |||||
extid_version: Optional[int] = None, | |||||
*, | |||||
db: Db, | |||||
cur=None, | |||||
) -> List[ExtID]: | ) -> List[ExtID]: | ||||
extids = [] | extids = [] | ||||
for row in db.extid_get_from_swhid_list(target_type.value, ids, cur): | if (extid_version is not None and extid_type is None) or ( | ||||
extid_version is None and extid_type is not None | |||||
): | |||||
raise ValueError("You must provide both extid_type and extid_version") | |||||
for row in db.extid_get_from_swhid_list( | |||||
target_type.value, | |||||
ids, | |||||
extid_version=extid_version, | |||||
extid_type=extid_type, | |||||
cur=cur, | |||||
): | |||||
if row[0] is not None: | if row[0] is not None: | ||||
extids.append(converters.db_to_extid(dict(zip(db.extid_cols, row)))) | extids.append(converters.db_to_extid(dict(zip(db.extid_cols, row)))) | ||||
return extids | return extids | ||||
@timed | @timed | ||||
@db_transaction() | @db_transaction() | ||||
def extid_add(self, ids: List[ExtID], *, db: Db, cur=None) -> Dict[str, int]: | def extid_add(self, ids: List[ExtID], *, db: Db, cur=None) -> Dict[str, int]: | ||||
extid = [ | extid = [ | ||||
▲ Show 20 Lines • Show All 831 Lines • Show Last 20 Lines |