Skip to content

Commit

Permalink
✨ Actually update the cache TTL comparatee
Browse files Browse the repository at this point in the history
  • Loading branch information
malted committed Sep 5, 2024
1 parent 5dae8db commit 22854d5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "replit-takeout"
version = "1.7.4"
version = "1.7.5"
edition = "2021"
authors = ["Ben Dixon <malted@malted.dev>"]

Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ async fn rocket() -> _ {
.manage(State {
token_to_id_cache: tokio::sync::RwLock::new(HashMap::new()),
stats_cache: tokio::sync::RwLock::new((
AggregateStats::default(),
chrono::offset::Utc::now(),
airtable::aggregates().await.expect("airtable aggregates"),
Utc::now(),
)),
})
.attach(cors.to_cors().unwrap())
Expand Down Expand Up @@ -186,6 +186,7 @@ async fn get_stats(state: &rocket::State<State>) -> Option<Json<AggregateStats>>

if seconds_ago > 5 {
state.stats_cache.write().await.0 = airtable::aggregates().await.ok()?;
state.stats_cache.write().await.1 = Utc::now();
info!(
"Refreshing stats cache ({seconds_ago}) :): {:?}",
state.stats_cache.read().await.0
Expand All @@ -197,8 +198,7 @@ async fn get_stats(state: &rocket::State<State>) -> Option<Json<AggregateStats>>
)
}

let stats = state.stats_cache.read().await.0.clone();
Some(Json(stats))
Some(Json(state.stats_cache.read().await.0))
}

async fn airtable_loop() -> Result<()> {
Expand Down

0 comments on commit 22854d5

Please sign in to comment.