From 10da700d8832b8a36ed88e036e4699a8b4a5b86b Mon Sep 17 00:00:00 2001 From: jouzo <15011228+Jouzo@users.noreply.github.com> Date: Mon, 4 Nov 2024 15:27:33 +0000 Subject: [PATCH] Remove clone --- lib/ain-ocean/src/api/oracle.rs | 29 ++++++++++++++--------------- lib/ain-ocean/src/indexer/oracle.rs | 15 +++++++-------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/lib/ain-ocean/src/api/oracle.rs b/lib/ain-ocean/src/api/oracle.rs index 7a7a94f33f..d1b309f63c 100644 --- a/lib/ain-ocean/src/api/oracle.rs +++ b/lib/ain-ocean/src/api/oracle.rs @@ -96,34 +96,33 @@ async fn get_feed( let key = (token, currency, txid); - let price_feed_list = ctx + let oracle_price_feeds = ctx .services .oracle_price_feed .by_id .list(None, SortOrder::Descending)? .paginate(&query) .flatten() - .collect::>(); - - let mut oracle_price_feeds = Vec::new(); - - for ((token, currency, oracle_id, txid), feed) in &price_feed_list { - if key.0.eq(token) && key.1.eq(currency) && key.2.eq(oracle_id) { + .into_iter() + .filter(|((token, currency, oracle_id, _), _)| { + key.0.eq(token) && key.1.eq(currency) && key.2.eq(oracle_id) + }) + .map(|((token, currency, oracle_id, txid), feed)| { let amount = Decimal::from(feed.amount) / Decimal::from(COIN); - oracle_price_feeds.push(OraclePriceFeedResponse { + OraclePriceFeedResponse { id: format!("{}-{}-{}-{}", token, currency, oracle_id, txid), key: format!("{}-{}-{}", token, currency, oracle_id), sort: hex::encode(feed.block.height.to_string() + &txid.to_string()), - token: token.to_owned(), - currency: currency.to_owned(), - oracle_id: oracle_id.to_owned(), - txid: *txid, + token, + currency, + oracle_id, + txid, time: feed.time, amount: amount.normalize().to_string(), block: feed.block.clone(), - }); - } - } + } + }) + .collect::>(); Ok(ApiPagedResponse::of( oracle_price_feeds, diff --git a/lib/ain-ocean/src/indexer/oracle.rs b/lib/ain-ocean/src/indexer/oracle.rs index 48a92f8dc2..295ddbcbd6 100644 --- a/lib/ain-ocean/src/indexer/oracle.rs +++ b/lib/ain-ocean/src/indexer/oracle.rs @@ -110,19 +110,18 @@ impl Index for RemoveOracle { let oracle_id = self.oracle_id; services.oracle.by_id.delete(&oracle_id)?; - let (_, previous) = get_previous_oracle(services, oracle_id)? - .context(NotFoundIndexSnafu { + let (_, mut previous) = + get_previous_oracle(services, oracle_id)?.context(NotFoundIndexSnafu { action: IndexAction::Index, r#type: "RemoveOracle".to_string(), id: oracle_id.to_string(), })?; - for PriceFeed { token, currency } in &previous.price_feeds { - services.oracle_token_currency.by_id.delete(&( - token.to_owned(), - currency.to_owned(), - oracle_id, - ))?; + for PriceFeed { token, currency } in previous.price_feeds.drain(..) { + services + .oracle_token_currency + .by_id + .delete(&(token, currency, oracle_id))?; } Ok(())