From 8248b36199e245ee567d125e32e5438c0113796b Mon Sep 17 00:00:00 2001 From: shufps Date: Tue, 21 Nov 2023 09:33:05 +0100 Subject: [PATCH] fixed writing to cache --- src/bin/inx-chronicle/api/explorer/routes.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/bin/inx-chronicle/api/explorer/routes.rs b/src/bin/inx-chronicle/api/explorer/routes.rs index 6c8224ee3..043e9737c 100644 --- a/src/bin/inx-chronicle/api/explorer/routes.rs +++ b/src/bin/inx-chronicle/api/explorer/routes.rs @@ -351,7 +351,7 @@ async fn richest_addresses_ledger_analytics( RichestAddressesQuery { top, ledger_index }: RichestAddressesQuery, ) -> ApiResult { let ledger_index = resolve_ledger_index(&database, ledger_index).await?; - let cache = RICHEST_ADDRESSES_CACHE.write().await; + let mut cache = RICHEST_ADDRESSES_CACHE.write().await; let seconds_until_midnight = calculate_seconds_until_midnight(); if let Some(cached_data) = &*cache { @@ -392,10 +392,7 @@ async fn richest_addresses_ledger_analytics( }; // Store the response in the cache - *RICHEST_ADDRESSES_CACHE.write().await = Some(RichestCacheData { - last_updated: Instant::now(), - data: response.clone(), - }); + *cache = Some(RichestCacheData { last_updated: Instant::now(), data: response.clone() }); let refresh_elapsed = refresh_start.elapsed().unwrap(); info!("refreshing richest-addresses cache done. Took {:?}", refresh_elapsed); @@ -409,7 +406,7 @@ async fn token_distribution_ledger_analytics( LedgerIndex { ledger_index }: LedgerIndex, ) -> ApiResult { let ledger_index = resolve_ledger_index(&database, ledger_index).await?; - let cache = TOKEN_DISTRIBUTION_CACHE.write().await; + let mut cache = TOKEN_DISTRIBUTION_CACHE.write().await; let seconds_until_midnight = calculate_seconds_until_midnight(); if let Some(cached_data) = &*cache { @@ -432,10 +429,7 @@ async fn token_distribution_ledger_analytics( }; // Store the response in the cache - *TOKEN_DISTRIBUTION_CACHE.write().await = Some(TokenCacheData { - last_updated: Instant::now(), - data: response.clone(), - }); + *cache = Some(TokenCacheData { last_updated: Instant::now(), data: response.clone() }); let refresh_elapsed = refresh_start.elapsed().unwrap(); info!("refreshing token-distribution cache done. Took {:?}", refresh_elapsed);