diff --git a/rust/processor/src/models/object_models/v2_objects.rs b/rust/processor/src/models/object_models/v2_objects.rs index 9bc934da7..60a6f4b71 100644 --- a/rust/processor/src/models/object_models/v2_objects.rs +++ b/rust/processor/src/models/object_models/v2_objects.rs @@ -124,7 +124,6 @@ impl Object { match Self::get_current_object( conn, &resource.address, - txn_version, query_retries, query_retry_delay_ms, ) @@ -173,13 +172,12 @@ impl Object { pub async fn get_current_object( conn: &mut PgPoolConnection<'_>, object_address: &str, - transaction_version: i64, query_retries: u32, query_retry_delay_ms: u64, ) -> anyhow::Result { - let mut retries = 0; - while retries < query_retries { - retries += 1; + let mut tried = 0; + while tried < query_retries { + tried += 1; match CurrentObjectQuery::get_by_address(object_address, conn).await { Ok(res) => { return Ok(CurrentObject { @@ -192,16 +190,11 @@ impl Object { is_deleted: res.is_deleted, }); }, - Err(e) => { - warn!( - transaction_version, - error = ?e, - object_address, - retry_ms = query_retry_delay_ms, - "Failed to get object from current_objects table.", - ); - tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms)) - .await; + Err(_) => { + if tried < query_retries { + tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms)) + .await; + } }, } } diff --git a/rust/processor/src/models/stake_models/current_delegated_voter.rs b/rust/processor/src/models/stake_models/current_delegated_voter.rs index 2562af865..8915d83dd 100644 --- a/rust/processor/src/models/stake_models/current_delegated_voter.rs +++ b/rust/processor/src/models/stake_models/current_delegated_voter.rs @@ -190,16 +190,18 @@ impl CurrentDelegatedVoter { query_retries: u32, query_retry_delay_ms: u64, ) -> anyhow::Result { - let mut retried = 0; - while retried < query_retries { - retried += 1; + let mut tried = 0; + while tried < query_retries { + tried += 1; match CurrentDelegatedVoterQuery::get_by_table_handle(conn, table_handle).await { Ok(current_delegated_voter_query_result) => { return Ok(current_delegated_voter_query_result.delegation_pool_address); }, Err(_) => { - tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms)) - .await; + if tried < query_retries { + tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms)) + .await; + } }, } } @@ -215,9 +217,9 @@ impl CurrentDelegatedVoter { query_retries: u32, query_retry_delay_ms: u64, ) -> bool { - let mut retried = 0; - while retried < query_retries { - retried += 1; + let mut tried = 0; + while tried < query_retries { + tried += 1; match CurrentDelegatedVoterQuery::get_by_pk( conn, delegator_address, @@ -227,8 +229,10 @@ impl CurrentDelegatedVoter { { Ok(_) => return true, Err(_) => { - tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms)) - .await; + if tried < query_retries { + tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms)) + .await; + } }, } } diff --git a/rust/processor/src/models/stake_models/delegator_balances.rs b/rust/processor/src/models/stake_models/delegator_balances.rs index 11b29a773..0293574a6 100644 --- a/rust/processor/src/models/stake_models/delegator_balances.rs +++ b/rust/processor/src/models/stake_models/delegator_balances.rs @@ -374,16 +374,18 @@ impl CurrentDelegatorBalance { query_retries: u32, query_retry_delay_ms: u64, ) -> anyhow::Result { - let mut retried = 0; - while retried < query_retries { - retried += 1; + let mut tried = 0; + while tried < query_retries { + tried += 1; match CurrentDelegatorBalanceQuery::get_by_inactive_share_handle(conn, table_handle) .await { Ok(current_delegator_balance) => return Ok(current_delegator_balance.pool_address), Err(_) => { - tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms)) - .await; + if tried < query_retries { + tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms)) + .await; + } }, } } diff --git a/rust/processor/src/models/token_models/collection_datas.rs b/rust/processor/src/models/token_models/collection_datas.rs index 5b37a5f8c..57444dac4 100644 --- a/rust/processor/src/models/token_models/collection_datas.rs +++ b/rust/processor/src/models/token_models/collection_datas.rs @@ -178,14 +178,16 @@ impl CollectionData { query_retries: u32, query_retry_delay_ms: u64, ) -> anyhow::Result { - let mut retried = 0; - while retried < query_retries { - retried += 1; + let mut tried = 0; + while tried < query_retries { + tried += 1; match CurrentCollectionDataQuery::get_by_table_handle(conn, table_handle).await { Ok(current_collection_data) => return Ok(current_collection_data.creator_address), Err(_) => { - tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms)) - .await; + if tried < query_retries { + tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms)) + .await; + } }, } } diff --git a/rust/processor/src/models/token_v2_models/v2_collections.rs b/rust/processor/src/models/token_v2_models/v2_collections.rs index d15d366cd..f40f4551f 100644 --- a/rust/processor/src/models/token_v2_models/v2_collections.rs +++ b/rust/processor/src/models/token_v2_models/v2_collections.rs @@ -314,14 +314,16 @@ impl CollectionV2 { query_retries: u32, query_retry_delay_ms: u64, ) -> anyhow::Result { - let mut retried = 0; - while retried < query_retries { - retried += 1; + let mut tried = 0; + while tried < query_retries { + tried += 1; match Self::get_by_table_handle(conn, table_handle).await { Ok(creator) => return Ok(creator), Err(_) => { - tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms)) - .await; + if tried < query_retries { + tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms)) + .await; + } }, } } diff --git a/rust/processor/src/models/token_v2_models/v2_token_ownerships.rs b/rust/processor/src/models/token_v2_models/v2_token_ownerships.rs index deb86ee91..b53d53339 100644 --- a/rust/processor/src/models/token_v2_models/v2_token_ownerships.rs +++ b/rust/processor/src/models/token_v2_models/v2_token_ownerships.rs @@ -619,9 +619,9 @@ impl CurrentTokenOwnershipV2Query { query_retries: u32, query_retry_delay_ms: u64, ) -> anyhow::Result { - let mut retried = 0; - while retried < query_retries { - retried += 1; + let mut tried = 0; + while tried < query_retries { + tried += 1; match Self::get_latest_owned_nft_by_token_data_id_impl(conn, token_data_id).await { Ok(inner) => { return Ok(NFTOwnershipV2 { @@ -631,8 +631,10 @@ impl CurrentTokenOwnershipV2Query { }); }, Err(_) => { - tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms)) - .await; + if tried < query_retries { + tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms)) + .await; + } }, } }