From acd330aa2a6cbc072ad41582b5b5bf4bacfa5e52 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Tue, 8 May 2018 17:49:49 -0300 Subject: [PATCH] get claim info and channel name using a single query --- lbrynet/database/storage.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lbrynet/database/storage.py b/lbrynet/database/storage.py index 122f7a866..8c8d29717 100644 --- a/lbrynet/database/storage.py +++ b/lbrynet/database/storage.py @@ -718,16 +718,15 @@ class SQLiteStorage(object): return r def _get_claim(transaction): - claim_info = transaction.execute( - "select * from claim where claim_outpoint=?", (claim_outpoint, ) - ).fetchone() - result = _claim_response(*claim_info) - if result['channel_claim_id']: - channel_name_result = transaction.execute( - "select claim_name from claim where claim_id=?", (result['channel_claim_id'], ) - ).fetchone() - if channel_name_result: - result['channel_name'] = channel_name_result[0] + claim_info = transaction.execute("select 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 claim c where claim_outpoint = ?", + (claim_outpoint,)).fetchone() + channel_name = claim_info[-1] + result = _claim_response(*claim_info[:-1]) + if channel_name: + result['channel_name'] = channel_name return result result = yield self.db.runInteraction(_get_claim)