Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/storage/db.py
Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | def _convert_key(self, key, main_table="c"): | ||||
in {language, mimetype, ...}), table indexer_configuration | in {language, mimetype, ...}), table indexer_configuration | ||||
being aliased as 'i'. | being aliased as 'i'. | ||||
""" | """ | ||||
if key == "id": | if key == "id": | ||||
return "%s.id" % main_table | return "%s.id" % main_table | ||||
elif key == "tool_id": | elif key == "tool_id": | ||||
return "i.id as tool_id" | return "i.id as tool_id" | ||||
elif key == "licenses": | elif key == "license": | ||||
return ( | return ( | ||||
""" | """ | ||||
array(select name | ( | ||||
select name | |||||
from fossology_license | from fossology_license | ||||
where id = ANY( | where id = %s.license_id | ||||
array_agg(%s.license_id))) as licenses""" | ) | ||||
as licenses""" | |||||
% main_table | % main_table | ||||
) | ) | ||||
return key | return key | ||||
def _get_from_list(self, table, ids, cols, cur=None, id_col="id"): | def _get_from_list(self, table, ids, cols, cur=None, id_col="id"): | ||||
"""Fetches entries from the `table` such that their `id` field | """Fetches entries from the `table` such that their `id` field | ||||
(or whatever is given to `id_col`) is in `ids`. | (or whatever is given to `id_col`) is in `ids`. | ||||
Returns the columns `cols`. | Returns the columns `cols`. | ||||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | def content_ctags_search(self, expression, last_sha1, limit, cur=None): | ||||
yield from cur | yield from cur | ||||
content_fossology_license_cols = [ | content_fossology_license_cols = [ | ||||
"id", | "id", | ||||
"tool_id", | "tool_id", | ||||
"tool_name", | "tool_name", | ||||
"tool_version", | "tool_version", | ||||
"tool_configuration", | "tool_configuration", | ||||
"licenses", | "license", | ||||
] | ] | ||||
@stored_procedure("swh_mktemp_content_fossology_license") | @stored_procedure("swh_mktemp_content_fossology_license") | ||||
def mktemp_content_fossology_license(self, cur=None): | def mktemp_content_fossology_license(self, cur=None): | ||||
pass | pass | ||||
def content_fossology_license_add_from_temp(self, conflict_update, cur=None): | def content_fossology_license_add_from_temp(self, conflict_update, cur=None): | ||||
"""Add new licenses per content. | """Add new licenses per content. | ||||
Show All 14 Lines | def content_fossology_license_get_from_list(self, ids, cur=None): | ||||
yield from execute_values_generator( | yield from execute_values_generator( | ||||
cur, | cur, | ||||
""" | """ | ||||
select %s | select %s | ||||
from (values %%s) as t(id) | from (values %%s) as t(id) | ||||
inner join content_fossology_license c on t.id=c.id | inner join content_fossology_license c on t.id=c.id | ||||
inner join indexer_configuration i | inner join indexer_configuration i | ||||
on i.id=c.indexer_configuration_id | on i.id=c.indexer_configuration_id | ||||
group by c.id, i.id, i.tool_name, i.tool_version, | |||||
i.tool_configuration; | |||||
""" | """ | ||||
% ", ".join(keys), | % ", ".join(keys), | ||||
((_id,) for _id in ids), | ((_id,) for _id in ids), | ||||
) | ) | ||||
content_metadata_hash_keys = ["id", "indexer_configuration_id"] | content_metadata_hash_keys = ["id", "indexer_configuration_id"] | ||||
def content_metadata_missing_from_list(self, metadata, cur=None): | def content_metadata_missing_from_list(self, metadata, cur=None): | ||||
▲ Show 20 Lines • Show All 229 Lines • Show Last 20 Lines |