From 0be046aa58904cbf8ea40ed1fc1887cd0e063c09 Mon Sep 17 00:00:00 2001 From: bowenyang007 Date: Thu, 7 Dec 2023 10:38:55 -0800 Subject: [PATCH] [rust] Optimize look up fungible token query (#212) * Optimize look up fungible token query * fix logic --- .../v2_fungible_metadata.rs | 4 ++-- .../models/token_v2_models/v2_token_datas.rs | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/rust/processor/src/models/fungible_asset_models/v2_fungible_metadata.rs b/rust/processor/src/models/fungible_asset_models/v2_fungible_metadata.rs index e5cd2aa6c..b3661f364 100644 --- a/rust/processor/src/models/fungible_asset_models/v2_fungible_metadata.rs +++ b/rust/processor/src/models/fungible_asset_models/v2_fungible_metadata.rs @@ -149,7 +149,7 @@ impl FungibleAssetMetadataModel { } /// Try to see if an address is a fungible asset (not a token). We'll try a few times in case there is a race condition, - /// and if we can't find after 3 times, we'll assume that it's not a fungible asset. + /// and if we can't find after N times, we'll assume that it's not a fungible asset. /// TODO: An improvement is to combine this with is_address_token. To do this well we need /// a k-v store async fn query_is_address_fungible_asset( @@ -170,7 +170,7 @@ impl FungibleAssetMetadataModel { } /// TODO: Change this to a KV store - async fn get_by_asset_type( + pub async fn get_by_asset_type( conn: &mut PgPoolConnection<'_>, address: &str, ) -> anyhow::Result { diff --git a/rust/processor/src/models/token_v2_models/v2_token_datas.rs b/rust/processor/src/models/token_v2_models/v2_token_datas.rs index af6fd5733..4d31f3f3d 100644 --- a/rust/processor/src/models/token_v2_models/v2_token_datas.rs +++ b/rust/processor/src/models/token_v2_models/v2_token_datas.rs @@ -7,9 +7,12 @@ use super::v2_token_utils::{TokenStandard, TokenV2, TokenV2AggregatedDataMapping}; use crate::{ - models::token_models::{ - collection_datas::{QUERY_RETRIES, QUERY_RETRY_DELAY_MS}, - token_utils::TokenWriteSet, + models::{ + fungible_asset_models::v2_fungible_metadata::FungibleAssetMetadataModel, + token_models::{ + collection_datas::{QUERY_RETRIES, QUERY_RETRY_DELAY_MS}, + token_utils::TokenWriteSet, + }, }, schema::{current_token_datas_v2, token_datas_v2}, utils::{database::PgPoolConnection, util::standardize_address}, @@ -250,7 +253,7 @@ impl TokenDataV2 { } /// Try to see if an address is a token. We'll try a few times in case there is a race condition, - /// and if we can't find after 3 times, we'll assume that it's not a token. + /// and if we can't find after N times, we'll assume that it's not a token. /// TODO: An improvement is to combine this with is_address_coin. To do this well we need /// a k-v store async fn query_is_address_token(conn: &mut PgPoolConnection<'_>, address: &str) -> bool { @@ -260,6 +263,13 @@ impl TokenDataV2 { match Self::get_by_token_data_id(conn, address).await { Ok(_) => return true, Err(_) => { + // TODO: this'll unblock very short term but we should clean this up + if FungibleAssetMetadataModel::get_by_asset_type(conn, address) + .await + .is_ok() + { + return false; + } std::thread::sleep(std::time::Duration::from_millis(QUERY_RETRY_DELAY_MS)); }, }