Skip to content

Commit

Permalink
used the cache as mutex to prevent concurrent refreshs
Browse files Browse the repository at this point in the history
  • Loading branch information
shufps committed Jul 8, 2024
1 parent f62bb55 commit 50391e9
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 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.read().await;
let cache = RICHEST_ADDRESSES_CACHE.write().await;
let seconds_until_midnight = calculate_seconds_until_midnight();

if let Some(cached_data) = &*cache {
Expand All @@ -360,8 +360,6 @@ async fn richest_addresses_ledger_analytics(
}
}

drop(cache); // release the read lock

info!("refreshing richest-addresses cache ...");
let refresh_start = SystemTime::now();

Expand Down Expand Up @@ -411,7 +409,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.read().await;
let cache = TOKEN_DISTRIBUTION_CACHE.write().await;

let seconds_until_midnight = calculate_seconds_until_midnight();
if let Some(cached_data) = &*cache {
Expand All @@ -420,8 +418,6 @@ async fn token_distribution_ledger_analytics(
}
}

drop(cache); // release the read lock

info!("refreshing token-distribution cache ...");
let refresh_start = SystemTime::now();

Expand Down

0 comments on commit 50391e9

Please sign in to comment.