Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/db.py
Show First 20 Lines • Show All 644 Lines • ▼ Show 20 Lines | class Db(BaseDb): | ||||
origin_cols = ['id', 'type', 'url'] | origin_cols = ['id', 'type', 'url'] | ||||
def origin_get_with(self, origins, cur=None): | def origin_get_with(self, origins, cur=None): | ||||
"""Retrieve the origin id from its type and url if found.""" | """Retrieve the origin id from its type and url if found.""" | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
query = """SELECT %s FROM (VALUES %%s) as t(type, url) | query = """SELECT %s FROM (VALUES %%s) as t(type, url) | ||||
LEFT JOIN origin | LEFT JOIN origin | ||||
ON (t.type=origin.type AND t.url=origin.url) | ON ((t.type IS NULL OR t.type=origin.type) | ||||
AND t.url=origin.url) | |||||
""" % ','.join('origin.' + col for col in self.origin_cols) | """ % ','.join('origin.' + col for col in self.origin_cols) | ||||
yield from execute_values_generator( | yield from execute_values_generator( | ||||
cur, query, origins) | cur, query, origins) | ||||
def origin_get(self, ids, cur=None): | def origin_get(self, ids, cur=None): | ||||
"""Retrieve the origin per its identifier. | """Retrieve the origin per its identifier. | ||||
▲ Show 20 Lines • Show All 252 Lines • Show Last 20 Lines |