From e6c549c45775ffc0763313d2770dadfcb981f2fb Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 17 Sep 2019 10:25:40 -0400 Subject: [PATCH] remove redundant query from sync_missing_blobs --- lbry/lbry/extras/daemon/storage.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/lbry/lbry/extras/daemon/storage.py b/lbry/lbry/extras/daemon/storage.py index 820663ed9..6dfc16e1c 100644 --- a/lbry/lbry/extras/daemon/storage.py +++ b/lbry/lbry/extras/daemon/storage.py @@ -370,22 +370,18 @@ class SQLiteStorage(SQLiteMixin): def sync_missing_blobs(self, blob_files: typing.Set[str]) -> typing.Awaitable[typing.Set[str]]: def _sync_blobs(transaction: sqlite3.Connection) -> typing.Set[str]: - to_update = [ - (blob_hash, ) - for (blob_hash, ) in transaction.execute("select blob_hash from blob where status='finished'") - if blob_hash not in blob_files - ] + finished_blob_hashes = tuple( + blob_hash for (blob_hash, ) in transaction.execute( + "select blob_hash from blob where status='finished'" + ).fetchall() + ) + finished_blobs_set = set(finished_blob_hashes) + to_update_set = finished_blobs_set.difference(blob_files) transaction.executemany( "update blob set status='pending' where blob_hash=?", - to_update - ) - return { - blob_hash - for blob_hash, in _batched_select( - transaction, "select blob_hash from blob where status='finished' and blob_hash in {}", - list(blob_files) - ) - } + ((blob_hash, ) for blob_hash in to_update_set) + ).fetchall() + return blob_files.intersection(finished_blobs_set) return self.db.run(_sync_blobs) # # # # # # # # # stream functions # # # # # # # # #