Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/storage/db.py
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | def _convert_key(self, key, main_table='c'): | ||||
elif key == 'licenses': | elif key == 'licenses': | ||||
return ''' | return ''' | ||||
array(select name | array(select name | ||||
from fossology_license | from fossology_license | ||||
where id = ANY( | where id = ANY( | ||||
array_agg(%s.license_id))) as licenses''' % main_table | array_agg(%s.license_id))) as licenses''' % main_table | ||||
return key | return key | ||||
def _get_from_list(self, table, ids, cols, cur=None): | def _get_from_list(self, table, ids, cols, cur=None, id_col='id'): | ||||
"""Fetches entries from the `table` such that their `id` field | |||||
(or whatever is given to `id_col`) is in `ids`. | |||||
Returns the columns `cols`. | |||||
The `cur`sor is used to connect to the database. | |||||
""" | |||||
ardumont: Adding a docstring here now would be a sensible thing to do. | |||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
keys = map(self._convert_key, cols) | keys = map(self._convert_key, cols) | ||||
yield from execute_values_to_bytes( | query = """ | ||||
cur, """ | select {keys} | ||||
select %s | from (values %s) as t(id) | ||||
from (values %%s) as t(id) | inner join {table} c | ||||
inner join %s c | on c.{id_col}=t.id | ||||
on c.id=t.id | |||||
inner join indexer_configuration i | inner join indexer_configuration i | ||||
on c.indexer_configuration_id=i.id; | on c.indexer_configuration_id=i.id; | ||||
""" % (', '.join(keys), table), | """.format( | ||||
keys=', '.join(keys), | |||||
id_col=id_col, | |||||
table=table) | |||||
yield from execute_values_to_bytes( | |||||
cur, query, | |||||
((_id,) for _id in ids) | ((_id,) for _id in ids) | ||||
) | ) | ||||
def content_mimetype_get_from_list(self, ids, cur=None): | def content_mimetype_get_from_list(self, ids, cur=None): | ||||
yield from self._get_from_list( | yield from self._get_from_list( | ||||
'content_mimetype', ids, self.content_mimetype_cols, cur=cur) | 'content_mimetype', ids, self.content_mimetype_cols, cur=cur) | ||||
content_language_hash_keys = ['id', 'indexer_configuration_id'] | content_language_hash_keys = ['id', 'indexer_configuration_id'] | ||||
▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | class Db(BaseDb): | ||||
def revision_metadata_add_from_temp(self, conflict_update, cur=None): | def revision_metadata_add_from_temp(self, conflict_update, cur=None): | ||||
self._cursor(cur).execute("SELECT swh_revision_metadata_add(%s)", | self._cursor(cur).execute("SELECT swh_revision_metadata_add(%s)", | ||||
(conflict_update, )) | (conflict_update, )) | ||||
def revision_metadata_get_from_list(self, ids, cur=None): | def revision_metadata_get_from_list(self, ids, cur=None): | ||||
yield from self._get_from_list( | yield from self._get_from_list( | ||||
'revision_metadata', ids, self.revision_metadata_cols, cur=cur) | 'revision_metadata', ids, self.revision_metadata_cols, cur=cur) | ||||
origin_intrinsic_metadata_cols = [ | |||||
'origin_id', 'metadata', 'from_revision', | |||||
'tool_id', 'tool_name', 'tool_version', 'tool_configuration'] | |||||
@stored_procedure('swh_mktemp_origin_intrinsic_metadata') | |||||
def mktemp_origin_intrinsic_metadata(self, cur=None): pass | |||||
def origin_intrinsic_metadata_add_from_temp( | |||||
self, conflict_update, cur=None): | |||||
cur = self._cursor(cur) | |||||
cur.execute( | |||||
"SELECT swh_origin_intrinsic_metadata_add(%s)", | |||||
(conflict_update, )) | |||||
def origin_intrinsic_metadata_get_from_list(self, orig_ids, cur=None): | |||||
yield from self._get_from_list( | |||||
'origin_intrinsic_metadata', orig_ids, | |||||
self.origin_intrinsic_metadata_cols, cur=cur, | |||||
id_col='origin_id') | |||||
indexer_configuration_cols = ['id', 'tool_name', 'tool_version', | indexer_configuration_cols = ['id', 'tool_name', 'tool_version', | ||||
'tool_configuration'] | 'tool_configuration'] | ||||
@stored_procedure('swh_mktemp_indexer_configuration') | @stored_procedure('swh_mktemp_indexer_configuration') | ||||
def mktemp_indexer_configuration(self, cur=None): | def mktemp_indexer_configuration(self, cur=None): | ||||
pass | pass | ||||
def indexer_configuration_add_from_temp(self, cur=None): | def indexer_configuration_add_from_temp(self, cur=None): | ||||
Show All 20 Lines |
Adding a docstring here now would be a sensible thing to do.