From 06ce6d7088c5943a75937b4cfa768dc3d0ce1c9d Mon Sep 17 00:00:00 2001 From: POA <33550681+poa@users.noreply.github.com> Date: Fri, 9 Jun 2023 11:02:11 +0300 Subject: [PATCH] Simplify batches chunking --- apps/indexer/lib/indexer/fetcher/zkevm_txn_batch.ex | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/apps/indexer/lib/indexer/fetcher/zkevm_txn_batch.ex b/apps/indexer/lib/indexer/fetcher/zkevm_txn_batch.ex index 7aa3f074ab..c6c61d575b 100644 --- a/apps/indexer/lib/indexer/fetcher/zkevm_txn_batch.ex +++ b/apps/indexer/lib/indexer/fetcher/zkevm_txn_batch.ex @@ -152,16 +152,13 @@ defmodule Indexer.Fetcher.ZkevmTxnBatch do end defp handle_batch_range(start_batch_number, end_batch_number, json_rpc_named_arguments) do - chunks_number = ceil((end_batch_number - start_batch_number + 1) / @batch_range_size) - - chunk_range = Range.new(0, max(chunks_number - 1, 0), 1) - - Enum.each(chunk_range, fn current_chunk -> - chunk_start = start_batch_number + @batch_range_size * current_chunk - chunk_end = min(chunk_start + @batch_range_size - 1, end_batch_number) + start_batch_number..end_batch_number + |> Enum.chunk_every(@batch_range_size) + |> Enum.each(fn chunk -> + chunk_start = List.first(chunk) + chunk_end = List.last(chunk) log_batches_chunk_handling(chunk_start, chunk_end, start_batch_number, end_batch_number) - fetch_and_save_batches(chunk_start, chunk_end, json_rpc_named_arguments) end) end