Skip to content

Commit

Permalink
We took a better snapshot!
Browse files Browse the repository at this point in the history
  • Loading branch information
adayoung committed Dec 24, 2024
1 parent 9d4ebf7 commit 72441ae
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/paste.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,16 @@ pub async fn update_views(state: &runtime::AppState, do_sleep: bool) {
sleep(Duration::from_secs(state.config.update_views_interval)).await;
}

for entry in counter().iter() {
let paste_id = entry.key().clone();
let views = *entry.value();
let items: Vec<(String, i64)> = counter()
.iter()
.map(|entry| (entry.key().clone(), *entry.value() as i64))
.collect();

let paste_result = Paste::get(&state.db, &paste_id).await;
for (paste_id, views) in items.iter() {
let paste_result = Paste::get(&state.db, paste_id).await;
match paste_result {
Ok(paste) => {
paste.save_views(&state.db, views as i64).await;
paste.save_views(&state.db, *views).await;
}
Err(err) => {
if err.0 != StatusCode::NOT_FOUND {
Expand Down

0 comments on commit 72441ae

Please sign in to comment.