diff --git a/CHANGELOG.md b/CHANGELOG.md index cec26a165..a04286501 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ at anytime. ### Fixed * `blob_list` raising an error when blobs in a stream haven't yet been created * stopping a download from raising `NoneType object has no attribute finished_deferred` + * file manager startup locking up when there are many files for some channels ### Deprecated * diff --git a/lbrynet/database/storage.py b/lbrynet/database/storage.py index 00e1d9a4d..8241879cb 100644 --- a/lbrynet/database/storage.py +++ b/lbrynet/database/storage.py @@ -718,21 +718,28 @@ class SQLiteStorage(object): results = {} bind = "({})".format(','.join('?' for _ in range(len(stream_hashes)))) claim_infos = transaction.execute( - "select content_claim.stream_hash, c.*, " - "case when c.channel_claim_id is not null then " - "(select claim_name from claim where claim_id==c.channel_claim_id) " - "else null end as channel_name from content_claim " + "select content_claim.stream_hash, c.* from content_claim " "inner join claim c on c.claim_outpoint=content_claim.claim_outpoint " "and content_claim.stream_hash in {} order by c.rowid desc".format(bind), tuple(stream_hashes) ).fetchall() + channel_id_infos = {} + for claim_info in claim_infos: + if claim_info[7]: + streams = channel_id_infos.get(claim_info[7], []) + streams.append(claim_info[0]) + channel_id_infos[claim_info[7]] = streams for claim_info in claim_infos: - channel_name = claim_info[-1] stream_hash = claim_info[0] - result = _format_claim_response(*claim_info[1:-1]) - if channel_name: - result['channel_name'] = channel_name + result = _format_claim_response(*claim_info[1:]) results[stream_hash] = result + bind = "({})".format(','.join('?' for _ in range(len(channel_id_infos)))) + for claim_id, channel_name in transaction.execute( + "select claim_id, claim_name from claim where claim_id in {}".format(bind), + tuple(channel_id_infos.keys()) + ).fetchall(): + for stream_hash in channel_id_infos[claim_id]: + results[stream_hash]['channel_name'] = channel_name return results claims = yield self.db.runInteraction(_batch_get_claim)