Skip to content

Commit

Permalink
fix: batch migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludo Galabru committed Apr 9, 2023
1 parent a88cec4 commit ed8b7ad
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions components/chainhook-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed8b7ad

Please sign in to comment.