Reduce usage of async_trait (#5438)

* Reduce usage of async_trait

* use trait

* move dep
This commit is contained in:
Nutomic 2025-02-19 16:06:22 +00:00 committed by GitHub
parent 806f541fe5
commit a65d4034d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
51 changed files with 101 additions and 140 deletions

2
Cargo.lock generated
View file

@ -2695,7 +2695,6 @@ version = "1.0.0-alpha.0"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"anyhow", "anyhow",
"async-trait",
"bcrypt", "bcrypt",
"chrono", "chrono",
"deadpool", "deadpool",
@ -2760,7 +2759,6 @@ dependencies = [
"activitypub_federation", "activitypub_federation",
"actix-web", "actix-web",
"anyhow", "anyhow",
"async-trait",
"chrono", "chrono",
"diesel", "diesel",
"diesel-async", "diesel-async",

View file

@ -127,7 +127,6 @@ chrono = { version = "0.4.39", features = [
serde_json = { version = "1.0.138", features = ["preserve_order"] } serde_json = { version = "1.0.138", features = ["preserve_order"] }
base64 = "0.22.1" base64 = "0.22.1"
uuid = { version = "1.13.1", features = ["serde"] } uuid = { version = "1.13.1", features = ["serde"] }
async-trait = "0.1.86"
captcha = "0.0.9" captcha = "0.0.9"
anyhow = { version = "1.0.95", features = ["backtrace"] } anyhow = { version = "1.0.95", features = ["backtrace"] }
diesel_ltree = "0.4.0" diesel_ltree = "0.4.0"

View file

@ -35,7 +35,7 @@ url = { workspace = true }
futures = { workspace = true } futures = { workspace = true }
itertools = { workspace = true } itertools = { workspace = true }
uuid = { workspace = true } uuid = { workspace = true }
async-trait = { workspace = true } async-trait = "0.1.86"
anyhow = { workspace = true } anyhow = { workspace = true }
reqwest = { workspace = true } reqwest = { workspace = true }
moka.workspace = true moka.workspace = true

View file

@ -61,7 +61,6 @@ impl ActivityHandler for CreateOrUpdateNoteWrapper {
} }
} }
#[async_trait::async_trait]
impl InCommunity for CreateOrUpdateNoteWrapper { impl InCommunity for CreateOrUpdateNoteWrapper {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
// Same logic as in receive. In case this is a private message, an error is returned. // Same logic as in receive. In case this is a private message, an error is returned.

View file

@ -75,7 +75,6 @@ pub enum AnnouncableActivities {
Page(Page), Page(Page),
} }
#[async_trait::async_trait]
impl InCommunity for AnnouncableActivities { impl InCommunity for AnnouncableActivities {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
use AnnouncableActivities::*; use AnnouncableActivities::*;

View file

@ -82,7 +82,6 @@ impl Object for PostOrComment {
} }
} }
#[async_trait::async_trait]
impl InCommunity for PostOrComment { impl InCommunity for PostOrComment {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let cid = match self { let cid = match self {

View file

@ -40,7 +40,6 @@ pub struct BlockUser {
pub(crate) end_time: Option<DateTime<Utc>>, pub(crate) end_time: Option<DateTime<Utc>>,
} }
#[async_trait::async_trait]
impl InCommunity for BlockUser { impl InCommunity for BlockUser {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let target = self.target.dereference(context).await?; let target = self.target.dereference(context).await?;

View file

@ -33,7 +33,6 @@ pub struct UndoBlockUser {
pub(crate) restore_data: Option<bool>, pub(crate) restore_data: Option<bool>,
} }
#[async_trait::async_trait]
impl InCommunity for UndoBlockUser { impl InCommunity for UndoBlockUser {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let community = self.object.community(context).await?; let community = self.object.community(context).await?;

View file

@ -29,7 +29,6 @@ pub struct CollectionAdd {
pub(crate) id: Url, pub(crate) id: Url,
} }
#[async_trait::async_trait]
impl InCommunity for CollectionAdd { impl InCommunity for CollectionAdd {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let (community, _) = let (community, _) =

View file

@ -29,7 +29,6 @@ pub struct CollectionRemove {
pub(crate) id: Url, pub(crate) id: Url,
} }
#[async_trait::async_trait]
impl InCommunity for CollectionRemove { impl InCommunity for CollectionRemove {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let (community, _) = let (community, _) =

View file

@ -48,7 +48,6 @@ pub struct UndoLockPage {
pub(crate) id: Url, pub(crate) id: Url,
} }
#[async_trait::async_trait]
impl InCommunity for LockPage { impl InCommunity for LockPage {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let post = self.object.dereference(context).await?; let post = self.object.dereference(context).await?;
@ -57,7 +56,6 @@ impl InCommunity for LockPage {
} }
} }
#[async_trait::async_trait]
impl InCommunity for UndoLockPage { impl InCommunity for UndoLockPage {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let community = self.object.community(context).await?; let community = self.object.community(context).await?;

View file

@ -91,7 +91,6 @@ impl ReportObject {
} }
} }
#[async_trait::async_trait]
impl InCommunity for Report { impl InCommunity for Report {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let community = self.to[0].dereference(context).await?; let community = self.to[0].dereference(context).await?;

View file

@ -31,7 +31,6 @@ pub struct ResolveReport {
pub(crate) id: Url, pub(crate) id: Url,
} }
#[async_trait::async_trait]
impl InCommunity for ResolveReport { impl InCommunity for ResolveReport {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
self.object.community(context).await self.object.community(context).await

View file

@ -30,7 +30,6 @@ pub struct UpdateCommunity {
pub(crate) id: Url, pub(crate) id: Url,
} }
#[async_trait::async_trait]
impl InCommunity for UpdateCommunity { impl InCommunity for UpdateCommunity {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let community: ApubCommunity = self.object.id.clone().dereference(context).await?; let community: ApubCommunity = self.object.id.clone().dereference(context).await?;

View file

@ -30,7 +30,6 @@ pub struct CreateOrUpdateNote {
pub(crate) id: Url, pub(crate) id: Url,
} }
#[async_trait::async_trait]
impl InCommunity for CreateOrUpdateNote { impl InCommunity for CreateOrUpdateNote {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let post = self.object.get_parents(context).await?.0; let post = self.object.get_parents(context).await?.0;

View file

@ -26,7 +26,6 @@ pub struct CreateOrUpdatePage {
pub(crate) id: Url, pub(crate) id: Url,
} }
#[async_trait::async_trait]
impl InCommunity for CreateOrUpdatePage { impl InCommunity for CreateOrUpdatePage {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let community = self.object.community(context).await?; let community = self.object.community(context).await?;

View file

@ -44,7 +44,6 @@ pub struct Delete {
pub(crate) remove_data: Option<bool>, pub(crate) remove_data: Option<bool>,
} }
#[async_trait::async_trait]
impl InCommunity for Delete { impl InCommunity for Delete {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let community_id = match DeletableObjects::read_from_db(self.object.id(), context).await? { let community_id = match DeletableObjects::read_from_db(self.object.id(), context).await? {

View file

@ -31,7 +31,6 @@ pub struct UndoDelete {
pub(crate) cc: Vec<Url>, pub(crate) cc: Vec<Url>,
} }
#[async_trait::async_trait]
impl InCommunity for UndoDelete { impl InCommunity for UndoDelete {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let community = self.object.community(context).await?; let community = self.object.community(context).await?;

View file

@ -18,7 +18,6 @@ pub struct UndoVote {
pub(crate) id: Url, pub(crate) id: Url,
} }
#[async_trait::async_trait]
impl InCommunity for UndoVote { impl InCommunity for UndoVote {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let community = self.object.community(context).await?; let community = self.object.community(context).await?;

View file

@ -47,7 +47,6 @@ impl From<&VoteType> for i16 {
} }
} }
#[async_trait::async_trait]
impl InCommunity for Vote { impl InCommunity for Vote {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let community = self let community = self

View file

@ -9,7 +9,7 @@ use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::newtypes::DbUrl; use lemmy_db_schema::newtypes::DbUrl;
use lemmy_utils::error::LemmyResult; use lemmy_utils::error::LemmyResult;
use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::collections::HashMap; use std::{collections::HashMap, future::Future};
use url::Url; use url::Url;
pub mod activities; pub mod activities;
@ -80,9 +80,11 @@ impl<Kind: Id + DeserializeOwned + Send> IdOrNestedObject<Kind> {
} }
} }
#[async_trait::async_trait]
pub trait InCommunity { pub trait InCommunity {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity>; fn community(
&self,
context: &Data<LemmyContext>,
) -> impl Future<Output = LemmyResult<ApubCommunity>> + Send;
} }
#[cfg(test)] #[cfg(test)]

View file

@ -87,7 +87,6 @@ impl Note {
} }
} }
#[async_trait::async_trait]
impl InCommunity for Note { impl InCommunity for Note {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let (post, _) = self.get_parents(context).await?; let (post, _) = self.get_parents(context).await?;

View file

@ -226,7 +226,6 @@ impl ActivityHandler for Page {
} }
} }
#[async_trait::async_trait]
impl InCommunity for Page { impl InCommunity for Page {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
let community = match &self.attributed_to { let community = match &self.attributed_to {

View file

@ -65,7 +65,6 @@ diesel-async = { workspace = true, features = [
], optional = true } ], optional = true }
regex = { workspace = true, optional = true } regex = { workspace = true, optional = true }
diesel_ltree = { workspace = true, optional = true } diesel_ltree = { workspace = true, optional = true }
async-trait = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
deadpool = { version = "0.12.2", optional = true, features = ["rt_tokio_1"] } deadpool = { version = "0.12.2", optional = true, features = ["rt_tokio_1"] }
ts-rs = { workspace = true, optional = true } ts-rs = { workspace = true, optional = true }

View file

@ -153,7 +153,6 @@ pub fn comment_select_remove_deletes() -> _ {
) )
} }
#[async_trait]
impl Crud for Comment { impl Crud for Comment {
type InsertForm = CommentInsertForm; type InsertForm = CommentInsertForm;
type UpdateForm = CommentUpdateForm; type UpdateForm = CommentUpdateForm;
@ -178,7 +177,6 @@ impl Crud for Comment {
} }
} }
#[async_trait]
impl Likeable for CommentLike { impl Likeable for CommentLike {
type Form = CommentLikeForm; type Form = CommentLikeForm;
type IdType = CommentId; type IdType = CommentId;
@ -211,7 +209,6 @@ impl Likeable for CommentLike {
} }
} }
#[async_trait]
impl Saveable for CommentSaved { impl Saveable for CommentSaved {
type Form = CommentSavedForm; type Form = CommentSavedForm;
async fn save( async fn save(

View file

@ -9,7 +9,6 @@ use crate::{
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
#[async_trait]
impl Crud for CommentReply { impl Crud for CommentReply {
type InsertForm = CommentReplyInsertForm; type InsertForm = CommentReplyInsertForm;
type UpdateForm = CommentReplyUpdateForm; type UpdateForm = CommentReplyUpdateForm;

View file

@ -16,7 +16,6 @@ use diesel::{
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_utils::error::LemmyResult; use lemmy_utils::error::LemmyResult;
#[async_trait]
impl Reportable for CommentReport { impl Reportable for CommentReport {
type Form = CommentReportForm; type Form = CommentReportForm;
type IdType = CommentReportId; type IdType = CommentReportId;

View file

@ -53,7 +53,6 @@ use lemmy_utils::{
}; };
use url::Url; use url::Url;
#[async_trait]
impl Crud for Community { impl Crud for Community {
type InsertForm = CommunityInsertForm; type InsertForm = CommunityInsertForm;
type UpdateForm = CommunityUpdateForm; type UpdateForm = CommunityUpdateForm;
@ -86,7 +85,6 @@ impl Crud for Community {
} }
} }
#[async_trait]
impl Joinable for CommunityModerator { impl Joinable for CommunityModerator {
type Form = CommunityModeratorForm; type Form = CommunityModeratorForm;
async fn join( async fn join(
@ -356,7 +354,6 @@ impl CommunityModerator {
} }
} }
#[async_trait]
impl Bannable for CommunityPersonBan { impl Bannable for CommunityPersonBan {
type Form = CommunityPersonBanForm; type Form = CommunityPersonBanForm;
async fn ban( async fn ban(
@ -458,7 +455,6 @@ impl Queryable<sql_types::Nullable<crate::schema::sql_types::CommunityFollowerSt
} }
} }
#[async_trait]
impl Followable for CommunityFollower { impl Followable for CommunityFollower {
type Form = CommunityFollowerForm; type Form = CommunityFollowerForm;
async fn follow(pool: &mut DbPool<'_>, form: &CommunityFollowerForm) -> Result<Self, Error> { async fn follow(pool: &mut DbPool<'_>, form: &CommunityFollowerForm) -> Result<Self, Error> {
@ -505,7 +501,6 @@ impl Followable for CommunityFollower {
} }
} }
#[async_trait]
impl ApubActor for Community { impl ApubActor for Community {
async fn read_from_apub_id( async fn read_from_apub_id(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,

View file

@ -55,7 +55,6 @@ impl CommunityBlock {
} }
} }
#[async_trait]
impl Blockable for CommunityBlock { impl Blockable for CommunityBlock {
type Form = CommunityBlockForm; type Form = CommunityBlockForm;
async fn block(pool: &mut DbPool<'_>, community_block_form: &Self::Form) -> Result<Self, Error> { async fn block(pool: &mut DbPool<'_>, community_block_form: &Self::Form) -> Result<Self, Error> {

View file

@ -16,7 +16,6 @@ use diesel::{
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_utils::error::LemmyResult; use lemmy_utils::error::LemmyResult;
#[async_trait]
impl Reportable for CommunityReport { impl Reportable for CommunityReport {
type Form = CommunityReportForm; type Form = CommunityReportForm;
type IdType = CommunityReportId; type IdType = CommunityReportId;

View file

@ -14,7 +14,6 @@ use crate::{
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
#[async_trait]
impl Crud for CustomEmoji { impl Crud for CustomEmoji {
type InsertForm = CustomEmojiInsertForm; type InsertForm = CustomEmojiInsertForm;
type UpdateForm = CustomEmojiUpdateForm; type UpdateForm = CustomEmojiUpdateForm;

View file

@ -53,7 +53,6 @@ impl InstanceBlock {
} }
} }
#[async_trait]
impl Blockable for InstanceBlock { impl Blockable for InstanceBlock {
type Form = InstanceBlockForm; type Form = InstanceBlockForm;
async fn block(pool: &mut DbPool<'_>, instance_block_form: &Self::Form) -> Result<Self, Error> { async fn block(pool: &mut DbPool<'_>, instance_block_form: &Self::Form) -> Result<Self, Error> {

View file

@ -35,7 +35,6 @@ use crate::{
use diesel::{dsl::insert_into, result::Error, QueryDsl}; use diesel::{dsl::insert_into, result::Error, QueryDsl};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
#[async_trait]
impl Crud for AdminPurgePerson { impl Crud for AdminPurgePerson {
type InsertForm = AdminPurgePersonForm; type InsertForm = AdminPurgePersonForm;
type UpdateForm = AdminPurgePersonForm; type UpdateForm = AdminPurgePersonForm;
@ -62,7 +61,6 @@ impl Crud for AdminPurgePerson {
} }
} }
#[async_trait]
impl Crud for AdminPurgeCommunity { impl Crud for AdminPurgeCommunity {
type InsertForm = AdminPurgeCommunityForm; type InsertForm = AdminPurgeCommunityForm;
type UpdateForm = AdminPurgeCommunityForm; type UpdateForm = AdminPurgeCommunityForm;
@ -89,7 +87,6 @@ impl Crud for AdminPurgeCommunity {
} }
} }
#[async_trait]
impl Crud for AdminPurgePost { impl Crud for AdminPurgePost {
type InsertForm = AdminPurgePostForm; type InsertForm = AdminPurgePostForm;
type UpdateForm = AdminPurgePostForm; type UpdateForm = AdminPurgePostForm;
@ -116,7 +113,6 @@ impl Crud for AdminPurgePost {
} }
} }
#[async_trait]
impl Crud for AdminPurgeComment { impl Crud for AdminPurgeComment {
type InsertForm = AdminPurgeCommentForm; type InsertForm = AdminPurgeCommentForm;
type UpdateForm = AdminPurgeCommentForm; type UpdateForm = AdminPurgeCommentForm;
@ -143,7 +139,6 @@ impl Crud for AdminPurgeComment {
} }
} }
#[async_trait]
impl Crud for AdminAllowInstance { impl Crud for AdminAllowInstance {
type InsertForm = AdminAllowInstanceForm; type InsertForm = AdminAllowInstanceForm;
type UpdateForm = AdminAllowInstanceForm; type UpdateForm = AdminAllowInstanceForm;
@ -170,7 +165,6 @@ impl Crud for AdminAllowInstance {
} }
} }
#[async_trait]
impl Crud for AdminBlockInstance { impl Crud for AdminBlockInstance {
type InsertForm = AdminBlockInstanceForm; type InsertForm = AdminBlockInstanceForm;
type UpdateForm = AdminBlockInstanceForm; type UpdateForm = AdminBlockInstanceForm;

View file

@ -55,7 +55,6 @@ use crate::{
use diesel::{dsl::insert_into, result::Error, QueryDsl}; use diesel::{dsl::insert_into, result::Error, QueryDsl};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
#[async_trait]
impl Crud for ModRemovePost { impl Crud for ModRemovePost {
type InsertForm = ModRemovePostForm; type InsertForm = ModRemovePostForm;
type UpdateForm = ModRemovePostForm; type UpdateForm = ModRemovePostForm;
@ -95,7 +94,6 @@ impl ModRemovePost {
} }
} }
#[async_trait]
impl Crud for ModLockPost { impl Crud for ModLockPost {
type InsertForm = ModLockPostForm; type InsertForm = ModLockPostForm;
type UpdateForm = ModLockPostForm; type UpdateForm = ModLockPostForm;
@ -122,7 +120,6 @@ impl Crud for ModLockPost {
} }
} }
#[async_trait]
impl Crud for ModFeaturePost { impl Crud for ModFeaturePost {
type InsertForm = ModFeaturePostForm; type InsertForm = ModFeaturePostForm;
type UpdateForm = ModFeaturePostForm; type UpdateForm = ModFeaturePostForm;
@ -149,7 +146,6 @@ impl Crud for ModFeaturePost {
} }
} }
#[async_trait]
impl Crud for ModRemoveComment { impl Crud for ModRemoveComment {
type InsertForm = ModRemoveCommentForm; type InsertForm = ModRemoveCommentForm;
type UpdateForm = ModRemoveCommentForm; type UpdateForm = ModRemoveCommentForm;
@ -189,7 +185,6 @@ impl ModRemoveComment {
} }
} }
#[async_trait]
impl Crud for ModRemoveCommunity { impl Crud for ModRemoveCommunity {
type InsertForm = ModRemoveCommunityForm; type InsertForm = ModRemoveCommunityForm;
type UpdateForm = ModRemoveCommunityForm; type UpdateForm = ModRemoveCommunityForm;
@ -216,7 +211,6 @@ impl Crud for ModRemoveCommunity {
} }
} }
#[async_trait]
impl Crud for ModBanFromCommunity { impl Crud for ModBanFromCommunity {
type InsertForm = ModBanFromCommunityForm; type InsertForm = ModBanFromCommunityForm;
type UpdateForm = ModBanFromCommunityForm; type UpdateForm = ModBanFromCommunityForm;
@ -243,7 +237,6 @@ impl Crud for ModBanFromCommunity {
} }
} }
#[async_trait]
impl Crud for ModBan { impl Crud for ModBan {
type InsertForm = ModBanForm; type InsertForm = ModBanForm;
type UpdateForm = ModBanForm; type UpdateForm = ModBanForm;
@ -270,7 +263,6 @@ impl Crud for ModBan {
} }
} }
#[async_trait]
impl Crud for ModHideCommunity { impl Crud for ModHideCommunity {
type InsertForm = ModHideCommunityForm; type InsertForm = ModHideCommunityForm;
type UpdateForm = ModHideCommunityForm; type UpdateForm = ModHideCommunityForm;
@ -297,7 +289,6 @@ impl Crud for ModHideCommunity {
} }
} }
#[async_trait]
impl Crud for ModAddCommunity { impl Crud for ModAddCommunity {
type InsertForm = ModAddCommunityForm; type InsertForm = ModAddCommunityForm;
type UpdateForm = ModAddCommunityForm; type UpdateForm = ModAddCommunityForm;
@ -324,7 +315,6 @@ impl Crud for ModAddCommunity {
} }
} }
#[async_trait]
impl Crud for ModTransferCommunity { impl Crud for ModTransferCommunity {
type InsertForm = ModTransferCommunityForm; type InsertForm = ModTransferCommunityForm;
type UpdateForm = ModTransferCommunityForm; type UpdateForm = ModTransferCommunityForm;
@ -351,7 +341,6 @@ impl Crud for ModTransferCommunity {
} }
} }
#[async_trait]
impl Crud for ModAdd { impl Crud for ModAdd {
type InsertForm = ModAddForm; type InsertForm = ModAddForm;
type UpdateForm = ModAddForm; type UpdateForm = ModAddForm;

View file

@ -13,7 +13,6 @@ use crate::{
use diesel::{dsl::insert_into, result::Error, QueryDsl}; use diesel::{dsl::insert_into, result::Error, QueryDsl};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
#[async_trait]
impl Crud for OAuthProvider { impl Crud for OAuthProvider {
type InsertForm = OAuthProviderInsertForm; type InsertForm = OAuthProviderInsertForm;
type UpdateForm = OAuthProviderUpdateForm; type UpdateForm = OAuthProviderUpdateForm;

View file

@ -30,7 +30,6 @@ use lemmy_utils::{
}; };
use url::Url; use url::Url;
#[async_trait]
impl Crud for Person { impl Crud for Person {
type InsertForm = PersonInsertForm; type InsertForm = PersonInsertForm;
type UpdateForm = PersonUpdateForm; type UpdateForm = PersonUpdateForm;
@ -155,7 +154,6 @@ impl PersonInsertForm {
} }
} }
#[async_trait]
impl ApubActor for Person { impl ApubActor for Person {
async fn read_from_apub_id( async fn read_from_apub_id(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
@ -204,7 +202,6 @@ impl ApubActor for Person {
} }
} }
#[async_trait]
impl Followable for PersonFollower { impl Followable for PersonFollower {
type Form = PersonFollowerForm; type Form = PersonFollowerForm;
async fn follow(pool: &mut DbPool<'_>, form: &PersonFollowerForm) -> Result<Self, Error> { async fn follow(pool: &mut DbPool<'_>, form: &PersonFollowerForm) -> Result<Self, Error> {

View file

@ -60,7 +60,6 @@ impl PersonBlock {
} }
} }
#[async_trait]
impl Blockable for PersonBlock { impl Blockable for PersonBlock {
type Form = PersonBlockForm; type Form = PersonBlockForm;
async fn block( async fn block(

View file

@ -13,7 +13,6 @@ use crate::{
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
#[async_trait]
impl Crud for PersonCommentMention { impl Crud for PersonCommentMention {
type InsertForm = PersonCommentMentionInsertForm; type InsertForm = PersonCommentMentionInsertForm;
type UpdateForm = PersonCommentMentionUpdateForm; type UpdateForm = PersonCommentMentionUpdateForm;

View file

@ -13,7 +13,6 @@ use crate::{
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
#[async_trait]
impl Crud for PersonPostMention { impl Crud for PersonPostMention {
type InsertForm = PersonPostMentionInsertForm; type InsertForm = PersonPostMentionInsertForm;
type UpdateForm = PersonPostMentionUpdateForm; type UpdateForm = PersonPostMentionUpdateForm;

View file

@ -46,7 +46,6 @@ use lemmy_utils::{
settings::structs::Settings, settings::structs::Settings,
}; };
#[async_trait]
impl Crud for Post { impl Crud for Post {
type InsertForm = PostInsertForm; type InsertForm = PostInsertForm;
type UpdateForm = PostUpdateForm; type UpdateForm = PostUpdateForm;
@ -280,7 +279,6 @@ impl Post {
} }
} }
#[async_trait]
impl Likeable for PostLike { impl Likeable for PostLike {
type Form = PostLikeForm; type Form = PostLikeForm;
type IdType = PostId; type IdType = PostId;
@ -309,7 +307,6 @@ impl Likeable for PostLike {
} }
} }
#[async_trait]
impl Saveable for PostSaved { impl Saveable for PostSaved {
type Form = PostSavedForm; type Form = PostSavedForm;
async fn save(pool: &mut DbPool<'_>, post_saved_form: &PostSavedForm) -> Result<Self, Error> { async fn save(pool: &mut DbPool<'_>, post_saved_form: &PostSavedForm) -> Result<Self, Error> {

View file

@ -16,7 +16,6 @@ use diesel::{
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_utils::error::LemmyResult; use lemmy_utils::error::LemmyResult;
#[async_trait]
impl Reportable for PostReport { impl Reportable for PostReport {
type Form = PostReportForm; type Form = PostReportForm;
type IdType = PostReportId; type IdType = PostReportId;

View file

@ -12,7 +12,6 @@ use diesel_async::RunQueryDsl;
use lemmy_utils::{error::LemmyResult, settings::structs::Settings}; use lemmy_utils::{error::LemmyResult, settings::structs::Settings};
use url::Url; use url::Url;
#[async_trait]
impl Crud for PrivateMessage { impl Crud for PrivateMessage {
type InsertForm = PrivateMessageInsertForm; type InsertForm = PrivateMessageInsertForm;
type UpdateForm = PrivateMessageUpdateForm; type UpdateForm = PrivateMessageUpdateForm;

View file

@ -15,7 +15,6 @@ use diesel::{
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_utils::error::{FederationError, LemmyResult}; use lemmy_utils::error::{FederationError, LemmyResult};
#[async_trait]
impl Reportable for PrivateMessageReport { impl Reportable for PrivateMessageReport {
type Form = PrivateMessageReportForm; type Form = PrivateMessageReportForm;
type IdType = PrivateMessageReportId; type IdType = PrivateMessageReportId;

View file

@ -12,7 +12,6 @@ use crate::{
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
#[async_trait]
impl Crud for RegistrationApplication { impl Crud for RegistrationApplication {
type InsertForm = RegistrationApplicationInsertForm; type InsertForm = RegistrationApplicationInsertForm;
type UpdateForm = RegistrationApplicationUpdateForm; type UpdateForm = RegistrationApplicationUpdateForm;

View file

@ -13,7 +13,6 @@ use diesel_async::RunQueryDsl;
use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
use url::Url; use url::Url;
#[async_trait]
impl Crud for Site { impl Crud for Site {
type InsertForm = SiteInsertForm; type InsertForm = SiteInsertForm;
type UpdateForm = SiteUpdateForm; type UpdateForm = SiteUpdateForm;

View file

@ -9,7 +9,6 @@ use diesel::{insert_into, result::Error, QueryDsl};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_utils::error::LemmyResult; use lemmy_utils::error::LemmyResult;
#[async_trait]
impl Crud for Tag { impl Crud for Tag {
type InsertForm = TagInsertForm; type InsertForm = TagInsertForm;

View file

@ -8,7 +8,6 @@ use crate::{
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
#[async_trait]
impl Crud for Tagline { impl Crud for Tagline {
type InsertForm = TaglineInsertForm; type InsertForm = TaglineInsertForm;
type UpdateForm = TaglineUpdateForm; type UpdateForm = TaglineUpdateForm;

View file

@ -9,10 +9,6 @@ extern crate diesel_derive_newtype;
#[macro_use] #[macro_use]
extern crate diesel_derive_enum; extern crate diesel_derive_enum;
#[cfg(feature = "full")]
#[macro_use]
extern crate async_trait;
pub mod aggregates; pub mod aggregates;
#[cfg(feature = "full")] #[cfg(feature = "full")]
pub mod impls; pub mod impls;
@ -40,14 +36,10 @@ pub mod utils;
#[cfg(feature = "full")] #[cfg(feature = "full")]
pub mod schema_setup; pub mod schema_setup;
#[cfg(feature = "full")]
use diesel::query_source::AliasedField;
#[cfg(feature = "full")]
use schema::person;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use strum::{Display, EnumString}; use strum::{Display, EnumString};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use ts_rs::TS; use {diesel::query_source::AliasedField, schema::person, ts_rs::TS};
#[derive( #[derive(
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash, EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,

View file

@ -16,6 +16,7 @@ use diesel_async::{
RunQueryDsl, RunQueryDsl,
}; };
use lemmy_utils::error::LemmyResult; use lemmy_utils::error::LemmyResult;
use std::future::Future;
/// Returned by `diesel::delete` /// Returned by `diesel::delete`
pub type Delete<T> = DeleteStatement<<T as HasTable>::Table, <T as IntoUpdateTarget>::WhereClause>; pub type Delete<T> = DeleteStatement<<T as HasTable>::Table, <T as IntoUpdateTarget>::WhereClause>;
@ -27,7 +28,6 @@ pub type PrimaryKey<T> = <<T as HasTable>::Table as Table>::PrimaryKey;
// Trying to create default implementations for `create` and `update` results in a lifetime mess and // Trying to create default implementations for `create` and `update` results in a lifetime mess and
// weird compile errors. https://github.com/rust-lang/rust/issues/102211 // weird compile errors. https://github.com/rust-lang/rust/issues/102211
#[async_trait]
pub trait Crud: HasTable + Sized pub trait Crud: HasTable + Sized
where where
Self::Table: FindDsl<Self::IdType>, Self::Table: FindDsl<Self::IdType>,
@ -41,168 +41,212 @@ where
type UpdateForm; type UpdateForm;
type IdType: Send; type IdType: Send;
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error>; fn create(
pool: &mut DbPool<'_>,
form: &Self::InsertForm,
) -> impl Future<Output = Result<Self, Error>> + Send;
async fn read(pool: &mut DbPool<'_>, id: Self::IdType) -> Result<Self, Error> { fn read(
let query: Find<Self> = Self::table().find(id); pool: &mut DbPool<'_>,
let conn = &mut *get_conn(pool).await?; id: Self::IdType,
query.first(conn).await ) -> impl Future<Output = Result<Self, Error>> + Send
where
Self: Send,
{
async {
let query: Find<Self> = Self::table().find(id);
let conn = &mut *get_conn(pool).await?;
query.first(conn).await
}
} }
/// when you want to null out a column, you have to send Some(None)), since sending None means you /// when you want to null out a column, you have to send Some(None)), since sending None means you
/// just don't want to update that column. /// just don't want to update that column.
async fn update( fn update(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
id: Self::IdType, id: Self::IdType,
form: &Self::UpdateForm, form: &Self::UpdateForm,
) -> Result<Self, Error>; ) -> impl Future<Output = Result<Self, Error>> + Send;
async fn delete(pool: &mut DbPool<'_>, id: Self::IdType) -> Result<usize, Error> { fn delete(
let query: Delete<Find<Self>> = diesel::delete(Self::table().find(id)); pool: &mut DbPool<'_>,
let conn = &mut *get_conn(pool).await?; id: Self::IdType,
query.execute(conn).await ) -> impl Future<Output = Result<usize, Error>> + Send {
async {
let query: Delete<Find<Self>> = diesel::delete(Self::table().find(id));
let conn = &mut *get_conn(pool).await?;
query.execute(conn).await
}
} }
} }
#[async_trait]
pub trait Followable { pub trait Followable {
type Form; type Form;
async fn follow(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error> fn follow(
pool: &mut DbPool<'_>,
form: &Self::Form,
) -> impl Future<Output = Result<Self, Error>> + Send
where where
Self: Sized; Self: Sized;
async fn follow_accepted( fn follow_accepted(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
community_id: CommunityId, community_id: CommunityId,
person_id: PersonId, person_id: PersonId,
) -> Result<Self, Error> ) -> impl Future<Output = Result<Self, Error>> + Send
where where
Self: Sized; Self: Sized;
async fn unfollow(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<uplete::Count, Error> fn unfollow(
pool: &mut DbPool<'_>,
form: &Self::Form,
) -> impl Future<Output = Result<uplete::Count, Error>> + Send
where where
Self: Sized; Self: Sized;
} }
#[async_trait]
pub trait Joinable { pub trait Joinable {
type Form; type Form;
async fn join(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error> fn join(
pool: &mut DbPool<'_>,
form: &Self::Form,
) -> impl Future<Output = Result<Self, Error>> + Send
where where
Self: Sized; Self: Sized;
async fn leave(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<uplete::Count, Error> fn leave(
pool: &mut DbPool<'_>,
form: &Self::Form,
) -> impl Future<Output = Result<uplete::Count, Error>> + Send
where where
Self: Sized; Self: Sized;
} }
#[async_trait]
pub trait Likeable { pub trait Likeable {
type Form; type Form;
type IdType; type IdType;
async fn like(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error> fn like(
pool: &mut DbPool<'_>,
form: &Self::Form,
) -> impl Future<Output = Result<Self, Error>> + Send
where where
Self: Sized; Self: Sized;
async fn remove( fn remove(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
person_id: PersonId, person_id: PersonId,
item_id: Self::IdType, item_id: Self::IdType,
) -> Result<uplete::Count, Error> ) -> impl Future<Output = Result<uplete::Count, Error>> + Send
where where
Self: Sized; Self: Sized;
} }
#[async_trait]
pub trait Bannable { pub trait Bannable {
type Form; type Form;
async fn ban(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error> fn ban(
pool: &mut DbPool<'_>,
form: &Self::Form,
) -> impl Future<Output = Result<Self, Error>> + Send
where where
Self: Sized; Self: Sized;
async fn unban(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<uplete::Count, Error> fn unban(
pool: &mut DbPool<'_>,
form: &Self::Form,
) -> impl Future<Output = Result<uplete::Count, Error>> + Send
where where
Self: Sized; Self: Sized;
} }
#[async_trait]
pub trait Saveable { pub trait Saveable {
type Form; type Form;
async fn save(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error> fn save(
pool: &mut DbPool<'_>,
form: &Self::Form,
) -> impl Future<Output = Result<Self, Error>> + Send
where where
Self: Sized; Self: Sized;
async fn unsave(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<uplete::Count, Error> fn unsave(
pool: &mut DbPool<'_>,
form: &Self::Form,
) -> impl Future<Output = Result<uplete::Count, Error>> + Send
where where
Self: Sized; Self: Sized;
} }
#[async_trait]
pub trait Blockable { pub trait Blockable {
type Form; type Form;
async fn block(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error> fn block(
pool: &mut DbPool<'_>,
form: &Self::Form,
) -> impl Future<Output = Result<Self, Error>> + Send
where where
Self: Sized; Self: Sized;
async fn unblock(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<uplete::Count, Error> fn unblock(
pool: &mut DbPool<'_>,
form: &Self::Form,
) -> impl Future<Output = Result<uplete::Count, Error>> + Send
where where
Self: Sized; Self: Sized;
} }
#[async_trait]
pub trait Reportable { pub trait Reportable {
type Form; type Form;
type IdType; type IdType;
type ObjectIdType; type ObjectIdType;
async fn report(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error> fn report(
pool: &mut DbPool<'_>,
form: &Self::Form,
) -> impl Future<Output = Result<Self, Error>> + Send
where where
Self: Sized; Self: Sized;
async fn resolve( fn resolve(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
report_id: Self::IdType, report_id: Self::IdType,
resolver_id: PersonId, resolver_id: PersonId,
) -> Result<usize, Error> ) -> impl Future<Output = Result<usize, Error>> + Send
where where
Self: Sized; Self: Sized;
async fn resolve_apub( fn resolve_apub(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
object_id: Self::ObjectIdType, object_id: Self::ObjectIdType,
report_creator_id: PersonId, report_creator_id: PersonId,
resolver_id: PersonId, resolver_id: PersonId,
) -> LemmyResult<usize> ) -> impl Future<Output = LemmyResult<usize>> + Send
where where
Self: Sized; Self: Sized;
async fn resolve_all_for_object( fn resolve_all_for_object(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
comment_id_: Self::ObjectIdType, comment_id_: Self::ObjectIdType,
by_resolver_id: PersonId, by_resolver_id: PersonId,
) -> Result<usize, Error> ) -> impl Future<Output = Result<usize, Error>> + Send
where where
Self: Sized; Self: Sized;
async fn unresolve( fn unresolve(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
report_id: Self::IdType, report_id: Self::IdType,
resolver_id: PersonId, resolver_id: PersonId,
) -> Result<usize, Error> ) -> impl Future<Output = Result<usize, Error>> + Send
where where
Self: Sized; Self: Sized;
} }
#[async_trait]
pub trait ApubActor { pub trait ApubActor {
async fn read_from_apub_id( fn read_from_apub_id(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
object_id: &DbUrl, object_id: &DbUrl,
) -> Result<Option<Self>, Error> ) -> impl Future<Output = Result<Option<Self>, Error>> + Send
where where
Self: Sized; Self: Sized;
/// - actor_name is the name of the community or user to read. /// - actor_name is the name of the community or user to read.
/// - include_deleted, if true, will return communities or users that were deleted/removed /// - include_deleted, if true, will return communities or users that were deleted/removed
async fn read_from_name( fn read_from_name(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
actor_name: &str, actor_name: &str,
include_deleted: bool, include_deleted: bool,
) -> Result<Option<Self>, Error> ) -> impl Future<Output = Result<Option<Self>, Error>> + Send
where where
Self: Sized; Self: Sized;
async fn read_from_name_and_domain( fn read_from_name_and_domain(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
actor_name: &str, actor_name: &str,
protocol_domain: &str, protocol_domain: &str,
) -> Result<Option<Self>, Error> ) -> impl Future<Output = Result<Option<Self>, Error>> + Send
where where
Self: Sized; Self: Sized;
} }

View file

@ -33,7 +33,6 @@ tokio = { workspace = true, features = ["full"] }
tracing.workspace = true tracing.workspace = true
moka.workspace = true moka.workspace = true
tokio-util = "0.7.13" tokio-util = "0.7.13"
async-trait.workspace = true
[dev-dependencies] [dev-dependencies]
serial_test = { workspace = true } serial_test = { workspace = true }

View file

@ -1,5 +1,4 @@
use crate::util::LEMMY_TEST_FAST_FEDERATION; use crate::util::LEMMY_TEST_FAST_FEDERATION;
use async_trait::async_trait;
use chrono::{DateTime, TimeZone, Utc}; use chrono::{DateTime, TimeZone, Utc};
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::{CommunityId, DbUrl, InstanceId}, newtypes::{CommunityId, DbUrl, InstanceId},
@ -38,7 +37,6 @@ static FOLLOW_ADDITIONS_RECHECK_DELAY: LazyLock<chrono::TimeDelta> = LazyLock::n
static FOLLOW_REMOVALS_RECHECK_DELAY: LazyLock<chrono::TimeDelta> = static FOLLOW_REMOVALS_RECHECK_DELAY: LazyLock<chrono::TimeDelta> =
LazyLock::new(|| chrono::TimeDelta::try_hours(1).expect("TimeDelta out of bounds")); LazyLock::new(|| chrono::TimeDelta::try_hours(1).expect("TimeDelta out of bounds"));
#[async_trait]
pub trait DataSource: Send + Sync { pub trait DataSource: Send + Sync {
async fn read_site_from_instance_id(&self, instance_id: InstanceId) -> LemmyResult<Site>; async fn read_site_from_instance_id(&self, instance_id: InstanceId) -> LemmyResult<Site>;
async fn get_instance_followed_community_inboxes( async fn get_instance_followed_community_inboxes(
@ -57,7 +55,6 @@ impl DbDataSource {
} }
} }
#[async_trait]
impl DataSource for DbDataSource { impl DataSource for DbDataSource {
async fn read_site_from_instance_id(&self, instance_id: InstanceId) -> LemmyResult<Site> { async fn read_site_from_instance_id(&self, instance_id: InstanceId) -> LemmyResult<Site> {
Site::read_from_instance_id(&mut DbPool::Pool(&self.pool), instance_id).await Site::read_from_instance_id(&mut DbPool::Pool(&self.pool), instance_id).await
@ -231,7 +228,6 @@ mod tests {
use serde_json::json; use serde_json::json;
mock! { mock! {
DataSource {} DataSource {}
#[async_trait]
impl DataSource for DataSource { impl DataSource for DataSource {
async fn read_site_from_instance_id(&self, instance_id: InstanceId) -> LemmyResult<Site>; async fn read_site_from_instance_id(&self, instance_id: InstanceId) -> LemmyResult<Site>;
async fn get_instance_followed_community_inboxes( async fn get_instance_followed_community_inboxes(