From e8683a24bdb5e6e9fb5a2edc20249e0d4e74e0c7 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Mon, 6 May 2019 16:49:52 -0300 Subject: [PATCH] fix should_announce being set on stream creation --- lbrynet/extras/daemon/storage.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/lbrynet/extras/daemon/storage.py b/lbrynet/extras/daemon/storage.py index 28e8271ba..eb8d14921 100644 --- a/lbrynet/extras/daemon/storage.py +++ b/lbrynet/extras/daemon/storage.py @@ -153,21 +153,12 @@ def get_all_lbry_files(transaction: sqlite3.Connection) -> typing.List[typing.Di def store_stream(transaction: sqlite3.Connection, sd_blob: 'BlobFile', descriptor: 'StreamDescriptor'): - # add the head blob and set it to be announced - transaction.execute( - "insert or ignore into blob values (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?)", - ( - sd_blob.blob_hash, sd_blob.length, 0, 1, "pending", 0, 0, - descriptor.blobs[0].blob_hash, descriptor.blobs[0].length, 0, 1, "pending", 0, 0 - ) + # add all blobs, except the last one, which is empty + transaction.executemany( + "insert or ignore into blob values (?, ?, ?, ?, ?, ?, ?)", + [(blob.blob_hash, blob.length, 0, 0, "pending", 0, 0) + for blob in descriptor.blobs[:-1] + [sd_blob]] ) - # add the rest of the blobs with announcement off - if len(descriptor.blobs) > 2: - transaction.executemany( - "insert or ignore into blob values (?, ?, ?, ?, ?, ?, ?)", - [(blob.blob_hash, blob.length, 0, 0, "pending", 0, 0) - for blob in descriptor.blobs[1:-1]] - ) # associate the blobs to the stream transaction.execute("insert or ignore into stream values (?, ?, ?, ?, ?)", (descriptor.stream_hash, sd_blob.blob_hash, descriptor.key, @@ -179,6 +170,11 @@ def store_stream(transaction: sqlite3.Connection, sd_blob: 'BlobFile', descripto [(descriptor.stream_hash, blob.blob_hash, blob.blob_num, blob.iv) for blob in descriptor.blobs] ) + # ensure should_announce is set regardless if insert was ignored + transaction.execute( + "update blob set should_announce=1 where blob_hash in (?, ?)", + (sd_blob.blob_hash, descriptor.blobs[0].blob_hash,) + ) def delete_stream(transaction: sqlite3.Connection, descriptor: 'StreamDescriptor'):