From 5c280ef6f69ced30aa88decabe5e221813759381 Mon Sep 17 00:00:00 2001 From: asonix Date: Wed, 6 Jan 2021 13:49:23 -0600 Subject: [PATCH] Process outbound in new thread --- profiles/src/apub/actions/block.rs | 4 ++-- profiles/src/apub/actions/comment.rs | 10 +++++----- profiles/src/apub/actions/follow.rs | 4 ++-- profiles/src/apub/actions/follow_request.rs | 8 ++++---- profiles/src/apub/actions/profile.rs | 6 +++--- profiles/src/apub/actions/react.rs | 4 ++-- profiles/src/apub/actions/submission.rs | 10 +++++----- profiles/src/lib.rs | 8 +++++--- 8 files changed, 28 insertions(+), 26 deletions(-) diff --git a/profiles/src/apub/actions/block.rs b/profiles/src/apub/actions/block.rs index 58061fd..1eae49b 100644 --- a/profiles/src/apub/actions/block.rs +++ b/profiles/src/apub/actions/block.rs @@ -4,7 +4,7 @@ use crate::{ }; impl Action for CreateBlock { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let block = context.store.view.blocks.new( self.blocked_profile, self.blocked_by_profile, @@ -88,7 +88,7 @@ impl Action for CreateBlock { } impl Action for DeleteBlock { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let opt = context.store.view.blocks.remove(self.block_id)?; let block_apub_id = context.apub.apub_for_block(self.block_id)?.req()?; context.apub.delete_object(&block_apub_id)?; diff --git a/profiles/src/apub/actions/comment.rs b/profiles/src/apub/actions/comment.rs index 70e9d44..a0e24fd 100644 --- a/profiles/src/apub/actions/comment.rs +++ b/profiles/src/apub/actions/comment.rs @@ -1,10 +1,10 @@ use crate::{ apub::actions::{AnnounceComment, CreateComment, DeleteComment, DeleteReact, UpdateComment}, - Action, Outbound, Context, Error, Required, + Action, Context, Error, Outbound, Required, }; impl Action for CreateComment { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let submissioner_id = context .store .submissions @@ -79,13 +79,13 @@ impl Action for CreateComment { } impl Action for AnnounceComment { - fn perform(&self, _: &Context) -> Result>, Error> { + fn perform(&self, _: &Context) -> Result>, Error> { Ok(None) } } impl Action for UpdateComment { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let comment = context.store.comments.by_id(self.comment_id)?.req()?; let mut changes = comment.update(); @@ -126,7 +126,7 @@ fn delete_react(react_id: uuid::Uuid, context: &Context) -> Result<(), Error> { } impl Action for DeleteComment { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let opt = context.store.comments.delete(self.comment_id)?; context.store.view.comments.remove(self.comment_id); context.apub.delete_object(&self.note_apub_id)?; diff --git a/profiles/src/apub/actions/follow.rs b/profiles/src/apub/actions/follow.rs index 3dce8c5..9747b92 100644 --- a/profiles/src/apub/actions/follow.rs +++ b/profiles/src/apub/actions/follow.rs @@ -4,7 +4,7 @@ use crate::{ }; impl Action for UndoFollow { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let opt = context.store.view.follows.remove(self.follow_id)?; let accept_apub_id = context.apub.apub_for_follow(self.follow_id)?.req()?; context.apub.delete_object(&accept_apub_id)?; @@ -25,7 +25,7 @@ impl Action for UndoFollow { } impl Action for UndoAcceptFollow { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let opt = context.store.view.follows.remove(self.follow_id)?; let accept_apub_id = context.apub.apub_for_follow(self.follow_id)?.req()?; context.apub.delete_object(&accept_apub_id)?; diff --git a/profiles/src/apub/actions/follow_request.rs b/profiles/src/apub/actions/follow_request.rs index 717e2bf..6b44025 100644 --- a/profiles/src/apub/actions/follow_request.rs +++ b/profiles/src/apub/actions/follow_request.rs @@ -6,7 +6,7 @@ use crate::{ }; impl Action for CreateFollowRequest { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { context.check_block(self.followed_by_profile, self.followed_profile)?; let follow_request = context.store.view.follow_requests.new( @@ -40,7 +40,7 @@ impl Action for CreateFollowRequest { } impl Action for AcceptFollowRequest { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let opt = context .store .view @@ -82,7 +82,7 @@ impl Action for AcceptFollowRequest { } impl Action for RejectFollowRequest { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let opt = context .store .view @@ -118,7 +118,7 @@ impl Action for RejectFollowRequest { } impl Action for UndoFollowRequest { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let opt = context .store .view diff --git a/profiles/src/apub/actions/profile.rs b/profiles/src/apub/actions/profile.rs index 28a1d50..99cb863 100644 --- a/profiles/src/apub/actions/profile.rs +++ b/profiles/src/apub/actions/profile.rs @@ -4,7 +4,7 @@ use crate::{ }; impl Action for CreateProfile { - fn perform(&self, ctx: &Context) -> Result>, Error> { + fn perform(&self, ctx: &Context) -> Result>, Error> { let profile = ctx.store.profiles.create( self.owner_source.clone(), &self.handle, @@ -53,7 +53,7 @@ impl Action for CreateProfile { } impl Action for UpdateProfile { - fn perform(&self, ctx: &Context) -> Result>, Error> { + fn perform(&self, ctx: &Context) -> Result>, Error> { let profile = ctx.store.profiles.by_id(self.profile_id)?.req()?; let mut changes = profile.update(); @@ -115,7 +115,7 @@ fn delete_submission(submission_id: uuid::Uuid, ctx: &Context) -> Result<(), Err } impl Action for DeleteProfile { - fn perform(&self, ctx: &Context) -> Result>, Error> { + fn perform(&self, ctx: &Context) -> Result>, Error> { let profile_id = self.profile_id; let opt = ctx.store.profiles.delete(profile_id)?; diff --git a/profiles/src/apub/actions/react.rs b/profiles/src/apub/actions/react.rs index 7f9fc15..5c5d0c4 100644 --- a/profiles/src/apub/actions/react.rs +++ b/profiles/src/apub/actions/react.rs @@ -4,7 +4,7 @@ use crate::{ }; impl Action for CreateReact { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let submissioner_id = context .store .submissions @@ -62,7 +62,7 @@ impl Action for CreateReact { } impl Action for DeleteReact { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let react_id = self.react_id; let opt = context.store.reacts.delete(react_id)?; diff --git a/profiles/src/apub/actions/submission.rs b/profiles/src/apub/actions/submission.rs index 8763900..4becef2 100644 --- a/profiles/src/apub/actions/submission.rs +++ b/profiles/src/apub/actions/submission.rs @@ -2,12 +2,12 @@ use crate::{ apub::actions::{ AnnounceSubmission, CreateSubmission, DeleteComment, DeleteSubmission, UpdateSubmission, }, - Action, Outbound, Context, Error, Required, + Action, Context, Error, Outbound, Required, }; use std::collections::HashSet; impl Action for CreateSubmission { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let submission = context .store @@ -60,13 +60,13 @@ impl Action for CreateSubmission { } impl Action for AnnounceSubmission { - fn perform(&self, _: &Context) -> Result>, Error> { + fn perform(&self, _: &Context) -> Result>, Error> { Ok(None) } } impl Action for UpdateSubmission { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let submission_id = self.submission_id; let submission = context.store.submissions.by_id(submission_id)?.req()?; @@ -116,7 +116,7 @@ fn delete_comment(comment_id: uuid::Uuid, context: &Context) -> Result<(), Error } impl Action for DeleteSubmission { - fn perform(&self, context: &Context) -> Result>, Error> { + fn perform(&self, context: &Context) -> Result>, Error> { let submission_id = self.submission_id; let opt = context.store.submissions.delete(submission_id)?; diff --git a/profiles/src/lib.rs b/profiles/src/lib.rs index 7f5c572..dcbd888 100644 --- a/profiles/src/lib.rs +++ b/profiles/src/lib.rs @@ -120,7 +120,7 @@ enum RecoverableError { } pub trait Action { - fn perform(&self, context: &Context) -> Result>, Error>; + fn perform(&self, context: &Context) -> Result>, Error>; } pub trait Outbound { @@ -171,8 +171,10 @@ impl State { match action.perform(&ctx)? { Some(outbound) => { - ctx.deliver(&*outbound); - Ok(outbound.id()) + let id = outbound.id(); + let context_clone = ctx.clone(); + ctx.spawn_blocking(move || context_clone.deliver(&*outbound)); + Ok(id) } None => Ok(None), }