fix slow sqlite query

This commit is contained in:
Jack Robison 2018-03-19 13:31:05 -04:00
parent 1d9c996217
commit 43c73b9abf
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -423,12 +423,14 @@ class SQLiteStorage(object):
if only_completed:
lengths = transaction.execute(
"select b.blob_hash, b.blob_length from blob b "
"inner join stream_blob s ON b.blob_hash=s.blob_hash and b.status='finished'"
"inner join stream_blob s ON b.blob_hash=s.blob_hash and b.status='finished' and s.stream_hash=?",
(stream_hash, )
).fetchall()
else:
lengths = transaction.execute(
"select b.blob_hash, b.blob_length from blob b "
"inner join stream_blob s ON b.blob_hash=s.blob_hash"
"inner join stream_blob s ON b.blob_hash=s.blob_hash and s.stream_hash=?",
(stream_hash, )
).fetchall()
blob_length_dict = {}