From d0a24ef5844b72e93ab93b258de0756f0c9d8504 Mon Sep 17 00:00:00 2001 From: vrde Date: Wed, 25 Jul 2018 16:16:06 +0200 Subject: [PATCH] Problem: validation runs redundant queries (#2409) Solution: when a transaction is stored, the system splits it in three components, data, metadata, and the other fields of the transaction. When the system retrieves a transaction, it needs to make three different queries to reconstruct the original transaction. If a transaction does not exist, the system does three queries anyway, even if just one query is enough. This patch fixes this by doing the additional queries if and only if the transaction exists. --- bigchaindb/tendermint/lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bigchaindb/tendermint/lib.py b/bigchaindb/tendermint/lib.py index ed7aec15..5e238c94 100644 --- a/bigchaindb/tendermint/lib.py +++ b/bigchaindb/tendermint/lib.py @@ -254,10 +254,10 @@ class BigchainDB(object): def get_transaction(self, transaction_id, include_status=False): transaction = backend.query.get_transaction(self.connection, transaction_id) - asset = backend.query.get_asset(self.connection, transaction_id) - metadata = backend.query.get_metadata(self.connection, [transaction_id]) if transaction: + asset = backend.query.get_asset(self.connection, transaction_id) + metadata = backend.query.get_metadata(self.connection, [transaction_id]) if asset: transaction['asset'] = asset