Skip to content

Commit

Permalink
fixed writing to cache
Browse files Browse the repository at this point in the history
  • Loading branch information
shufps committed Jul 8, 2024
1 parent 50391e9 commit 8248b36
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/bin/inx-chronicle/api/explorer/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ async fn richest_addresses_ledger_analytics(
RichestAddressesQuery { top, ledger_index }: RichestAddressesQuery,
) -> ApiResult<RichestAddressesResponse> {
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 {
Expand Down Expand Up @@ -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);
Expand All @@ -409,7 +406,7 @@ async fn token_distribution_ledger_analytics(
LedgerIndex { ledger_index }: LedgerIndex,
) -> ApiResult<TokenDistributionResponse> {
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 {
Expand All @@ -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);
Expand Down

0 comments on commit 8248b36

Please sign in to comment.