From d6deaddc0a32e5c7dedf2832b8dca22bb0a922a5 Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Wed, 5 Aug 2020 16:09:41 +0800 Subject: [PATCH] Only query last_height when needed in decrypt_and_store_transaction() --- zcash_client_sqlite/src/scan.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/zcash_client_sqlite/src/scan.rs b/zcash_client_sqlite/src/scan.rs index 417d63bef..d22a48662 100644 --- a/zcash_client_sqlite/src/scan.rs +++ b/zcash_client_sqlite/src/scan.rs @@ -373,12 +373,15 @@ pub fn decrypt_and_store_transaction>( .ok_or(Error(ErrorKind::IncorrectHRPExtFVK))?; // Height is block height for mined transactions, and the "mempool height" (chain height + 1) for mempool transactions. - let last_height = data.query_row("SELECT MAX(height) FROM blocks", NO_PARAMS, |row| { - row.get(0).or(Ok(SAPLING_ACTIVATION_HEIGHT - 1)) - })?; let mut stmt_select_block = data.prepare("SELECT block FROM transactions WHERE txid = ?")?; let height = stmt_select_block.query_row(&[tx.txid().0.to_vec()], |row| { - row.get(0).or(Ok(last_height + 1)) + row.get(0).or({ + let last_height = + data.query_row("SELECT MAX(height) FROM blocks", NO_PARAMS, |row| { + row.get(0).or(Ok(SAPLING_ACTIVATION_HEIGHT - 1)) + })?; + Ok(last_height + 1) + }) })?; let outputs = decrypt_transaction::(height as u32, tx, &extfvks);