From ed8b7ad2f368b319f1c7f800d729e6bf693182d6 Mon Sep 17 00:00:00 2001 From: Ludo Galabru Date: Sat, 8 Apr 2023 21:03:25 -0400 Subject: [PATCH] fix: batch migration --- components/chainhook-cli/src/cli/mod.rs | 33 ++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/components/chainhook-cli/src/cli/mod.rs b/components/chainhook-cli/src/cli/mod.rs index 52c28d8e..4cad924d 100644 --- a/components/chainhook-cli/src/cli/mod.rs +++ b/components/chainhook-cli/src/cli/mod.rs @@ -588,21 +588,48 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> { let blocks_db = open_readwrite_hord_db_conn_rocks_db(&config.expected_cache_path(), &ctx)?; - for i in 0..783986 { + for i in 0..=300000 { match find_block_at_block_height_sqlite(i, &sqlite_db_conn_rw) { Some(block) => { insert_entry_in_blocks(i, &block, &blocks_db, &ctx); info!(ctx.expect_logger(), "Block #{} inserted", i); } None => { - info!(ctx.expect_logger(), "Block #{} missing", i); + error!(ctx.expect_logger(), "Block #{} missing", i); } } } + let _ = blocks_db.flush(); + delete_blocks_in_block_range_sqlite(0, 300000, &sqlite_db_conn_rw, &ctx); + for i in 300001..=500000 { + match find_block_at_block_height_sqlite(i, &sqlite_db_conn_rw) { + Some(block) => { + insert_entry_in_blocks(i, &block, &blocks_db, &ctx); + info!(ctx.expect_logger(), "Block #{} inserted", i); + } + None => { + info!(ctx.expect_logger(), "Block #{} missing", i); + } + } + } let _ = blocks_db.flush(); + delete_blocks_in_block_range_sqlite(300001, 500000, &sqlite_db_conn_rw, &ctx); - delete_blocks_in_block_range_sqlite(0, 783986, &sqlite_db_conn_rw, &ctx); + + for i in 500001..=783986 { + match find_block_at_block_height_sqlite(i, &sqlite_db_conn_rw) { + Some(block) => { + insert_entry_in_blocks(i, &block, &blocks_db, &ctx); + info!(ctx.expect_logger(), "Block #{} inserted", i); + } + None => { + info!(ctx.expect_logger(), "Block #{} missing", i); + } + } + } + let _ = blocks_db.flush(); + delete_blocks_in_block_range_sqlite(500001, 783986, &sqlite_db_conn_rw, &ctx); } // Sync