Try for a quick re-lock of the db in the announceer

This commit is contained in:
Natsu Kagami 2023-11-13 22:38:27 +01:00
parent ea75818c99
commit 822f07954f
Signed by: nki
GPG key ID: 55A032EB38B49ADB

View file

@ -45,10 +45,12 @@ impl youmubot_prelude::Announcer for Announcer {
channels: MemberToChannels, channels: MemberToChannels,
) -> Result<()> { ) -> Result<()> {
// For each user... // For each user...
let users = {
let data = d.read().await; let data = d.read().await;
let data = data.get::<OsuSavedUsers>().unwrap(); let data = data.get::<OsuSavedUsers>().unwrap();
data.all().await?
};
let now = chrono::Utc::now(); let now = chrono::Utc::now();
let users = data.all().await?;
users users
.into_iter() .into_iter()
.map(|mut osu_user| { .map(|mut osu_user| {
@ -78,7 +80,14 @@ impl youmubot_prelude::Announcer for Announcer {
println!("scanning {} done", osu_user.id); println!("scanning {} done", osu_user.id);
osu_user.last_update = now; osu_user.last_update = now;
osu_user.pp = v.try_into().unwrap(); osu_user.pp = v.try_into().unwrap();
data.save(osu_user).await.pls_ok(); ctx.data
.read()
.await
.get::<OsuSavedUsers>()
.unwrap()
.save(osu_user)
.await
.pls_ok();
} }
Err(e) => { Err(e) => {
eprintln!("osu: Cannot update {}: {}", osu_user.id, e); eprintln!("osu: Cannot update {}: {}", osu_user.id, e);