@@ -839,21 +839,23 @@ fn subtree_scan_progress(
839
839
fully_scanned_height : BlockHeight ,
840
840
chain_tip_height : BlockHeight ,
841
841
) -> Result < Option < Ratio < u64 > > , SqliteClientError > {
842
+ let mut stmt_scanned_count_from = conn. prepare_cached ( & format ! (
843
+ "SELECT SUM({output_count_col})
844
+ FROM blocks
845
+ WHERE :start_height <= height" ,
846
+ ) ) ?;
847
+
842
848
if fully_scanned_height == chain_tip_height {
843
849
// Compute the total blocks scanned since the wallet birthday
844
- conn. query_row (
845
- & format ! (
846
- "SELECT SUM({output_count_col})
847
- FROM blocks
848
- WHERE height >= :birthday_height" ,
849
- ) ,
850
- named_params ! [ ":birthday_height" : u32 :: from( birthday_height) ] ,
851
- |row| {
852
- let scanned = row. get :: < _ , Option < u64 > > ( 0 ) ?;
853
- Ok ( scanned. map ( |n| Ratio :: new ( n, n) ) )
854
- } ,
855
- )
856
- . map_err ( SqliteClientError :: from)
850
+ stmt_scanned_count_from
851
+ . query_row (
852
+ named_params ! [ ":start_height" : u32 :: from( birthday_height) ] ,
853
+ |row| {
854
+ let scanned = row. get :: < _ , Option < u64 > > ( 0 ) ?;
855
+ Ok ( scanned. map ( |n| Ratio :: new ( n, n) ) )
856
+ } ,
857
+ )
858
+ . map_err ( SqliteClientError :: from)
857
859
} else {
858
860
// Get the starting note commitment tree size from the wallet birthday, or failing that
859
861
// from the blocks table.
@@ -887,13 +889,8 @@ fn subtree_scan_progress(
887
889
. transpose ( ) ?;
888
890
889
891
// Compute the total blocks scanned so far above the starting height
890
- let scanned_count = conn. query_row (
891
- & format ! (
892
- "SELECT SUM({output_count_col})
893
- FROM blocks
894
- WHERE height > :start_height" ,
895
- ) ,
896
- named_params ! [ ":start_height" : u32 :: from( birthday_height) ] ,
892
+ let scanned_count = stmt_scanned_count_from. query_row (
893
+ named_params ! [ ":start_height" : u32 :: from( birthday_height + 1 ) ] ,
897
894
|row| row. get :: < _ , Option < u64 > > ( 0 ) ,
898
895
) ?;
899
896
0 commit comments