From 6da8967082c71be21a497918c593c1d910626556 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Thu, 16 Feb 2023 03:22:24 +0800 Subject: [PATCH] fix: use `walk_range` on `import_table_with_range` (#1364) Co-authored-by: Georgios Konstantopoulos Co-authored-by: Roman Krasiuk --- crates/storage/db/src/abstraction/table.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/storage/db/src/abstraction/table.rs b/crates/storage/db/src/abstraction/table.rs index 691d12db27..cd3fffbd89 100644 --- a/crates/storage/db/src/abstraction/table.rs +++ b/crates/storage/db/src/abstraction/table.rs @@ -101,19 +101,20 @@ pub trait TableImporter<'tx>: for<'a> DbTxMut<'a> { source_tx: &R, from: Option<::Key>, to: ::Key, - ) -> Result<(), Error> { + ) -> Result<(), Error> + where + T::Key: Default, + { let mut destination_cursor = self.cursor_write::()?; let mut source_cursor = source_tx.cursor_read::()?; - for row in source_cursor.walk(from)? { + let source_range = match from { + Some(from) => source_cursor.walk_range(from..=to), + None => source_cursor.walk_range(..=to), + }; + for row in source_range? { let (key, value) = row?; - let finished = key == to; - destination_cursor.append(key, value)?; - - if finished { - break - } } Ok(())