fix: delete invalid userblocks when viewing settings

This commit is contained in:
trisua 2025-05-09 23:03:31 -04:00
parent 9ce1161361
commit 246e54e1d0

View file

@ -30,7 +30,13 @@ impl DataManager {
let mut out = Vec::new();
for block in list {
out.push(self.get_user_by_id(block.receiver).await?);
out.push(match self.get_user_by_id(block.receiver).await {
Ok(ua) => ua,
Err(_) => {
self.delete_userblock_sudo(block.id).await?;
continue;
}
});
}
Ok(out)
@ -196,4 +202,26 @@ impl DataManager {
// return
Ok(())
}
pub async fn delete_userblock_sudo(&self, id: usize) -> Result<()> {
let conn = match self.connect().await {
Ok(c) => c,
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
};
let res = execute!(
&conn,
"DELETE FROM userblocks WHERE id = $1",
&[&(id as i64)]
);
if let Err(e) = res {
return Err(Error::DatabaseError(e.to_string()));
}
self.2.remove(format!("atto.userblock:{}", id)).await;
// return
Ok(())
}
}