Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/db.py
Show First 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | def content_missing_per_sha1(self, sha1s, cur=None): | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
yield from execute_values_generator(cur, """ | yield from execute_values_generator(cur, """ | ||||
SELECT t.sha1 FROM (VALUES %s) AS t(sha1) | SELECT t.sha1 FROM (VALUES %s) AS t(sha1) | ||||
WHERE NOT EXISTS ( | WHERE NOT EXISTS ( | ||||
SELECT 1 FROM content c WHERE c.sha1 = t.sha1 | SELECT 1 FROM content c WHERE c.sha1 = t.sha1 | ||||
)""", ((sha1,) for sha1 in sha1s)) | )""", ((sha1,) for sha1 in sha1s)) | ||||
def content_missing_per_sha1_git(self, contents, cur=None): | |||||
cur = self._cursor(cur) | |||||
yield from execute_values_generator(cur, """ | |||||
SELECT t.sha1_git FROM (VALUES %s) AS t(sha1_git) | |||||
WHERE NOT EXISTS ( | |||||
SELECT 1 FROM content c WHERE c.sha1_git = t.sha1_git | |||||
)""", ((sha1,) for sha1 in contents)) | |||||
def skipped_content_missing(self, contents, cur=None): | def skipped_content_missing(self, contents, cur=None): | ||||
if not contents: | if not contents: | ||||
return [] | return [] | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
query = """SELECT * FROM (VALUES %s) AS t (%s) | query = """SELECT * FROM (VALUES %s) AS t (%s) | ||||
WHERE not exists | WHERE not exists | ||||
(SELECT 1 FROM skipped_content s WHERE | (SELECT 1 FROM skipped_content s WHERE | ||||
Show All 11 Lines | class Db(BaseDb): | ||||
def snapshot_exists(self, snapshot_id, cur=None): | def snapshot_exists(self, snapshot_id, cur=None): | ||||
"""Check whether a snapshot with the given id exists""" | """Check whether a snapshot with the given id exists""" | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
cur.execute("""SELECT 1 FROM snapshot where id=%s""", (snapshot_id,)) | cur.execute("""SELECT 1 FROM snapshot where id=%s""", (snapshot_id,)) | ||||
return bool(cur.fetchone()) | return bool(cur.fetchone()) | ||||
def snapshot_missing_from_list(self, snapshots, cur=None): | |||||
cur = self._cursor(cur) | |||||
yield from execute_values_generator( | |||||
cur, """ | |||||
SELECT id FROM (VALUES %s) as t(id) | |||||
WHERE NOT EXISTS ( | |||||
SELECT 1 FROM snapshot d WHERE d.id = t.id | |||||
) | |||||
""", ((id,) for id in snapshots)) | |||||
def snapshot_add(self, snapshot_id, cur=None): | def snapshot_add(self, snapshot_id, cur=None): | ||||
"""Add a snapshot from the temporary table""" | """Add a snapshot from the temporary table""" | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
cur.execute("""SELECT swh_snapshot_add(%s)""", (snapshot_id,)) | cur.execute("""SELECT swh_snapshot_add(%s)""", (snapshot_id,)) | ||||
snapshot_count_cols = ['target_type', 'count'] | snapshot_count_cols = ['target_type', 'count'] | ||||
▲ Show 20 Lines • Show All 787 Lines • Show Last 20 Lines |