remove old stream on a publish update

This commit is contained in:
Jack Robison 2018-02-27 16:21:37 -05:00
parent d8a728e931
commit 91229aac6e
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
3 changed files with 23 additions and 0 deletions

View file

@ -40,6 +40,18 @@ class Publisher(object):
claim_dict['stream']['source']['contentType'] = get_content_type(file_path)
claim_dict['stream']['source']['version'] = "_0_0_1" # need current version here
claim_out = yield self.make_claim(name, bid, claim_dict, claim_address, change_address)
# check if we have a file already for this claim (if this is a publish update with a new stream)
old_stream_hashes = yield self.session.storage.get_stream_hashes_for_claim_id(claim_out['claim_id'])
if old_stream_hashes:
lbry_files = list(self.lbry_file_manager.lbry_files)
for lbry_file in lbry_files:
s_h = lbry_file.stream_hash
if s_h in old_stream_hashes:
yield self.lbry_file_manager.delete_lbry_file(lbry_file, delete_file=False)
old_stream_hashes.remove(s_h)
log.info("Removed old stream for claim update: %s", s_h)
yield self.session.storage.save_content_claim(
self.lbry_file.stream_hash, "%s:%i" % (claim_out['txid'], claim_out['nout'])
)

View file

@ -543,6 +543,14 @@ class SQLiteStorage(object):
# support info
yield self.save_supports(claim_id, claim_info['supports'])
def get_stream_hashes_for_claim_id(self, claim_id):
return self.run_and_return_list(
"select f.stream_hash from file f "
"inner join content_claim cc on f.stream_hash=cc.stream_hash "
"inner join claim c on c.claim_outpoint=cc.claim_outpoint and c.claim_id=?",
claim_id
)
def save_content_claim(self, stream_hash, claim_outpoint):
def _save_content_claim(transaction):
# get the claim id and serialized metadata

View file

@ -296,6 +296,9 @@ class ContentClaimStorageTests(StorageTest):
stored_content_claim = yield self.storage.get_content_claim(stream_hash)
self.assertDictEqual(stored_content_claim, fake_claim_info)
stream_hashes = yield self.storage.get_stream_hashes_for_claim_id(fake_claim_info['claim_id'])
self.assertListEqual(stream_hashes, [stream_hash])
# test that we can't associate a claim update with a new stream to the file
second_stream_hash, second_sd_hash = random_lbry_hash(), random_lbry_hash()
yield self.make_and_store_fake_stream(blob_count=2, stream_hash=second_stream_hash, sd_hash=second_sd_hash)