Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/postgresql/storage.py
Show First 20 Lines • Show All 1,399 Lines • ▼ Show 20 Lines | |||||
@db_transaction() | @db_transaction() | ||||
def metadata_fetcher_add( | def metadata_fetcher_add( | ||||
self, fetchers: List[MetadataFetcher], db=None, cur=None | self, fetchers: List[MetadataFetcher], db=None, cur=None | ||||
) -> Dict[str, int]: | ) -> Dict[str, int]: | ||||
fetchers = list(fetchers) | fetchers = list(fetchers) | ||||
self.journal_writer.metadata_fetcher_add(fetchers) | self.journal_writer.metadata_fetcher_add(fetchers) | ||||
count = 0 | count = 0 | ||||
for fetcher in fetchers: | for fetcher in fetchers: | ||||
if fetcher.metadata is None: | db.metadata_fetcher_add(fetcher.name, fetcher.version, cur=cur) | ||||
raise StorageArgumentException( | |||||
"MetadataFetcher.metadata may not be None in metadata_fetcher_add." | |||||
) | |||||
db.metadata_fetcher_add( | |||||
fetcher.name, fetcher.version, dict(fetcher.metadata), cur=cur | |||||
) | |||||
count += 1 | count += 1 | ||||
return {"metadata_fetcher:add": count} | return {"metadata_fetcher:add": count} | ||||
@timed | @timed | ||||
@db_transaction(statement_timeout=500) | @db_transaction(statement_timeout=500) | ||||
def metadata_fetcher_get( | def metadata_fetcher_get( | ||||
self, name: str, version: str, db=None, cur=None | self, name: str, version: str, db=None, cur=None | ||||
) -> Optional[MetadataFetcher]: | ) -> Optional[MetadataFetcher]: | ||||
row = db.metadata_fetcher_get(name, version, cur=cur) | row = db.metadata_fetcher_get(name, version, cur=cur) | ||||
if not row: | if not row: | ||||
return None | return None | ||||
return MetadataFetcher.from_dict(dict(zip(db.metadata_fetcher_cols, row))) | return MetadataFetcher.from_dict(dict(zip(db.metadata_fetcher_cols, row))) | ||||
@timed | @timed | ||||
@process_metrics | @process_metrics | ||||
@db_transaction() | @db_transaction() | ||||
def metadata_authority_add( | def metadata_authority_add( | ||||
self, authorities: List[MetadataAuthority], db=None, cur=None | self, authorities: List[MetadataAuthority], db=None, cur=None | ||||
) -> Dict[str, int]: | ) -> Dict[str, int]: | ||||
authorities = list(authorities) | authorities = list(authorities) | ||||
self.journal_writer.metadata_authority_add(authorities) | self.journal_writer.metadata_authority_add(authorities) | ||||
count = 0 | count = 0 | ||||
for authority in authorities: | for authority in authorities: | ||||
if authority.metadata is None: | db.metadata_authority_add(authority.type.value, authority.url, cur=cur) | ||||
raise StorageArgumentException( | |||||
"MetadataAuthority.metadata may not be None in " | |||||
"metadata_authority_add." | |||||
) | |||||
db.metadata_authority_add( | |||||
authority.type.value, authority.url, dict(authority.metadata), cur=cur | |||||
) | |||||
count += 1 | count += 1 | ||||
return {"metadata_authority:add": count} | return {"metadata_authority:add": count} | ||||
@timed | @timed | ||||
@db_transaction() | @db_transaction() | ||||
def metadata_authority_get( | def metadata_authority_get( | ||||
self, type: MetadataAuthorityType, url: str, db=None, cur=None | self, type: MetadataAuthorityType, url: str, db=None, cur=None | ||||
) -> Optional[MetadataAuthority]: | ) -> Optional[MetadataAuthority]: | ||||
Show All 27 Lines |