forked from mirrors/relay
Perform db action inline
This commit is contained in:
parent
cdef00f844
commit
4c373e562b
3 changed files with 17 additions and 16 deletions
|
@ -45,34 +45,32 @@ impl Db {
|
|||
Ok(self.actor.send(DbQuery(f)).await?.await?)
|
||||
}
|
||||
|
||||
pub fn remove_listener(&self, inbox: XsdAnyUri) {
|
||||
self.actor.do_send(DbQuery(move |pool: Pool| {
|
||||
pub async fn remove_listener(&self, inbox: XsdAnyUri) -> Result<(), MyError> {
|
||||
self.execute_inline(move |pool: Pool| {
|
||||
let inbox = inbox.clone();
|
||||
|
||||
async move {
|
||||
let conn = pool.get().await?;
|
||||
|
||||
remove_listener(&conn, &inbox).await.map_err(|e| {
|
||||
error!("Error removing listener, {}", e);
|
||||
e
|
||||
})
|
||||
remove_listener(&conn, &inbox).await
|
||||
}
|
||||
}));
|
||||
})
|
||||
.await?
|
||||
.map_err(MyError::from)
|
||||
}
|
||||
|
||||
pub fn add_listener(&self, inbox: XsdAnyUri) {
|
||||
self.actor.do_send(DbQuery(move |pool: Pool| {
|
||||
pub async fn add_listener(&self, inbox: XsdAnyUri) -> Result<(), MyError> {
|
||||
self.execute_inline(move |pool: Pool| {
|
||||
let inbox = inbox.clone();
|
||||
|
||||
async move {
|
||||
let conn = pool.get().await?;
|
||||
|
||||
add_listener(&conn, &inbox).await.map_err(|e| {
|
||||
error!("Error adding listener, {}", e);
|
||||
e
|
||||
})
|
||||
add_listener(&conn, &inbox).await
|
||||
}
|
||||
}));
|
||||
})
|
||||
.await?
|
||||
.map_err(MyError::from)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,9 @@ use tokio::sync::oneshot::error::RecvError;
|
|||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum MyError {
|
||||
#[error("Error in db, {0}")]
|
||||
DbError(#[from] anyhow::Error),
|
||||
|
||||
#[error("Couldn't parse key, {0}")]
|
||||
Key(#[from] KeyError),
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ async fn handle_undo(
|
|||
}
|
||||
|
||||
let inbox = actor.inbox().to_owned();
|
||||
db.remove_listener(inbox);
|
||||
db.remove_listener(inbox).await?;
|
||||
|
||||
let undo = generate_undo_follow(state, &actor.id, &my_id)?;
|
||||
|
||||
|
@ -169,7 +169,7 @@ async fn handle_follow(
|
|||
let follow = generate_follow(state, &actor.id, &my_id)?;
|
||||
|
||||
let inbox = actor.inbox().to_owned();
|
||||
db.add_listener(inbox);
|
||||
db.add_listener(inbox).await?;
|
||||
|
||||
let client2 = client.clone();
|
||||
let inbox = actor.inbox().clone();
|
||||
|
|
Loading…
Reference in a new issue