From 54be63fb54d59736c21f83a54220f253fd927993 Mon Sep 17 00:00:00 2001 From: Danil Date: Wed, 13 Jul 2022 14:02:29 +0300 Subject: [PATCH] Fix query for getting txs for address (#2272) Signed-off-by: deniallugo --- core/lib/storage/src/chain/operations_ext/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/lib/storage/src/chain/operations_ext/mod.rs b/core/lib/storage/src/chain/operations_ext/mod.rs index cfaa0d79f..4be59951a 100644 --- a/core/lib/storage/src/chain/operations_ext/mod.rs +++ b/core/lib/storage/src/chain/operations_ext/mod.rs @@ -1188,7 +1188,7 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> { }; let token_query = if token.is_some() { - "AND a.token = $2" + "AND token = $2" } else { "" }; @@ -1208,7 +1208,9 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> { b.block_index, Null::bigint as batch_id FROM executed_priority_operations as b - WHERE EXISTS ( SELECT 1 FROM tx_filters as a WHERE a.tx_hash = b.tx_hash AND a.address = $1 {} ) + JOIN + (SELECT DISTINCT tx_hash FROM tx_filters WHERE address = $1 {}) + as a ON a.tx_hash = b.tx_hash {} "#, token_query, query_direction @@ -1244,7 +1246,7 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> { }; let token_query = if token.is_some() { - "AND a.token = $2" + "AND token = $2" } else { "" }; @@ -1264,7 +1266,9 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> { txs.block_index, txs.batch_id FROM executed_transactions as txs - WHERE EXISTS ( SELECT 1 FROM tx_filters as a WHERE a.tx_hash = txs.tx_hash AND a.address = $1 {} ) + JOIN + (SELECT DISTINCT tx_hash FROM tx_filters WHERE address = $1 {}) + as a ON a.tx_hash = txs.tx_hash {} "#, token_query, query_direction