diff --git a/swh/storage/db.py b/swh/storage/db.py --- a/swh/storage/db.py +++ b/swh/storage/db.py @@ -124,11 +124,22 @@ SELECT 1 FROM content c WHERE c.sha1 = t.sha1 )""", ((sha1,) for sha1 in sha1s)) - def skipped_content_missing_from_temp(self, cur=None): - cur = self._cursor(cur) - - cur.execute("""SELECT sha1, sha1_git, sha256, blake2s256 - FROM swh_skipped_content_missing()""") + def skipped_content_missing(self, contents, cur=None): + if not contents: + return [] + cur = self._cursor(cur) + + query = """SELECT * FROM (VALUES %s) AS t (%s) + WHERE not exists + (SELECT 1 FROM skipped_content s WHERE + s.sha1 is not distinct from t.sha1 and + s.sha1_git is not distinct from t.sha1_git and + s.sha256 is not distinct from t.sha256);""" % \ + ((', '.join('%s' for _ in contents)), + ', '.join(self.content_hash_keys)) + cur.execute(query, + [tuple(cont[key] for key in self.content_hash_keys) + for cont in contents]) yield from cur diff --git a/swh/storage/storage.py b/swh/storage/storage.py --- a/swh/storage/storage.py +++ b/swh/storage/storage.py @@ -487,13 +487,8 @@ iterable: missing signatures """ - keys = db.content_hash_keys - - db.mktemp('skipped_content', cur) - db.copy_to(contents, 'tmp_skipped_content', - keys + ['length', 'reason'], cur) - - yield from db.skipped_content_missing_from_temp(cur) + for content in db.skipped_content_missing(contents, cur): + yield dict(zip(db.content_hash_keys, content)) @db_transaction() def content_find(self, content, db=None, cur=None):