From 5a9338a27f20634ed9f15cfbc2f6b4a8d6e59b13 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Tue, 2 Mar 2021 19:58:18 -0300 Subject: [PATCH] use a dict on set_reference --- lbry/schema/result.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lbry/schema/result.py b/lbry/schema/result.py index 509b425c5..7b2f31a3f 100644 --- a/lbry/schema/result.py +++ b/lbry/schema/result.py @@ -13,14 +13,11 @@ NOT_FOUND = ErrorMessage.Code.Name(ErrorMessage.NOT_FOUND) BLOCKED = ErrorMessage.Code.Name(ErrorMessage.BLOCKED) -def set_reference(reference, claim_hash, rows): - if claim_hash: - for txo in rows: - if claim_hash == txo['claim_hash']: - reference.tx_hash = txo['txo_hash'][:32] - reference.nout = struct.unpack(' bytes: + extra_txo_rows = {row['claim_hash']: row for row in extra_txo_rows} page = OutputsMessage() page.offset = offset if total is not None: @@ -163,12 +161,12 @@ class Outputs: blocked.to_message(page, extra_txo_rows) for row in txo_rows: cls.row_to_message(row, page.txos.add(), extra_txo_rows) - for row in extra_txo_rows: + for row in extra_txo_rows.values(): cls.row_to_message(row, page.extra_txos.add(), extra_txo_rows) return page.SerializeToString() @classmethod - def row_to_message(cls, txo, txo_message, extra_txo_rows): + def row_to_message(cls, txo, txo_message, extra_row_dict: dict): if isinstance(txo, Exception): txo_message.error.text = txo.args[0] if isinstance(txo, ValueError): @@ -177,7 +175,7 @@ class Outputs: txo_message.error.code = ErrorMessage.NOT_FOUND elif isinstance(txo, ResolveCensoredError): txo_message.error.code = ErrorMessage.BLOCKED - set_reference(txo_message.error.blocked.channel, txo.censor_hash, extra_txo_rows) + set_reference(txo_message.error.blocked.channel, extra_row_dict.get(txo.censor_hash)) return txo_message.tx_hash = txo['txo_hash'][:32] txo_message.nout, = struct.unpack('