Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/db.py
Show First 20 Lines • Show All 954 Lines • ▼ Show 20 Lines | def origin_id_get_by_url(self, origins, cur=None): | ||||
LEFT JOIN origin ON t.url = origin.url | LEFT JOIN origin ON t.url = origin.url | ||||
""" | """ | ||||
for row in execute_values_generator(cur, query, ((url,) for url in origins)): | for row in execute_values_generator(cur, query, ((url,) for url in origins)): | ||||
yield row[0] | yield row[0] | ||||
origin_get_range_cols = ["id", "url"] | origin_get_range_cols = ["id", "url"] | ||||
def origin_get_range(self, origin_from=1, origin_count=100, cur=None): | def origin_get_range(self, origin_from: int = 1, origin_count: int = 100, cur=None): | ||||
"""Retrieve ``origin_count`` origins whose ids are greater | """Retrieve ``origin_count`` origins whose ids are greater | ||||
or equal than ``origin_from``. | or equal than ``origin_from``. | ||||
Origins are sorted by id before retrieving them. | Origins are sorted by id before retrieving them. | ||||
Args: | Args: | ||||
origin_from (int): the minimum id of origins to retrieve | origin_from: the minimum id of origins to retrieve | ||||
origin_count (int): the maximum number of origins to retrieve | origin_count: the maximum number of origins to retrieve | ||||
""" | """ | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
query = """SELECT %s | query = """SELECT %s | ||||
FROM origin WHERE id >= %%s | FROM origin WHERE id >= %%s | ||||
ORDER BY id LIMIT %%s | ORDER BY id LIMIT %%s | ||||
""" % ",".join( | """ % ",".join( | ||||
self.origin_get_range_cols | self.origin_get_range_cols | ||||
▲ Show 20 Lines • Show All 350 Lines • Show Last 20 Lines |