From acc9ca1aed10c39efdd91cefece066e035a1fe80 Mon Sep 17 00:00:00 2001 From: dull b Date: Wed, 5 Jul 2023 06:33:53 +0000 Subject: [PATCH] aaaa --- crates/api_common/src/context.rs | 2 +- crates/api_common/src/utils.rs | 40 +-- crates/apub/src/activities/block/mod.rs | 7 +- crates/apub/src/api/resolve_object.rs | 2 +- crates/apub/src/lib.rs | 4 +- crates/apub/src/mentions.rs | 4 +- crates/apub/src/objects/instance.rs | 4 +- crates/apub/src/protocol/objects/mod.rs | 10 +- .../src/aggregates/comment_aggregates.rs | 13 +- .../src/aggregates/community_aggregates.rs | 6 +- .../src/aggregates/person_aggregates.rs | 6 +- .../src/aggregates/person_post_aggregates.rs | 17 +- .../src/aggregates/post_aggregates.rs | 13 +- .../src/aggregates/site_aggregates.rs | 6 +- crates/db_schema/src/impls/activity.rs | 28 +- crates/db_schema/src/impls/actor_language.rs | 53 ++-- crates/db_schema/src/impls/captcha_answer.rs | 16 +- crates/db_schema/src/impls/comment.rs | 63 +++-- crates/db_schema/src/impls/comment_reply.rs | 31 ++- crates/db_schema/src/impls/comment_report.rs | 17 +- crates/db_schema/src/impls/community.rs | 83 +++--- crates/db_schema/src/impls/community_block.rs | 16 +- crates/db_schema/src/impls/custom_emoji.rs | 31 ++- .../db_schema/src/impls/email_verification.rs | 17 +- .../src/impls/federation_allowlist.rs | 9 +- .../src/impls/federation_blocklist.rs | 9 +- crates/db_schema/src/impls/instance.rs | 29 ++- crates/db_schema/src/impls/language.rs | 17 +- crates/db_schema/src/impls/local_site.rs | 24 +- .../src/impls/local_site_rate_limit.rs | 20 +- crates/db_schema/src/impls/local_user.rs | 36 +-- crates/db_schema/src/impls/moderator.rs | 239 +++++++++++------- .../src/impls/password_reset_request.rs | 33 ++- crates/db_schema/src/impls/person.rs | 65 +++-- crates/db_schema/src/impls/person_block.rs | 20 +- crates/db_schema/src/impls/person_mention.rs | 28 +- crates/db_schema/src/impls/post.rs | 97 ++++--- crates/db_schema/src/impls/post_report.rs | 17 +- crates/db_schema/src/impls/private_message.rs | 29 ++- .../src/impls/private_message_report.rs | 17 +- .../src/impls/registration_application.rs | 22 +- crates/db_schema/src/impls/secret.rs | 8 +- crates/db_schema/src/impls/site.rs | 27 +- crates/db_schema/src/impls/tagline.rs | 13 +- crates/db_schema/src/traits.rs | 59 +++-- crates/db_schema/src/utils.rs | 35 ++- crates/db_views/src/comment_report_view.rs | 10 +- crates/db_views/src/comment_view.rs | 12 +- crates/db_views/src/custom_emoji_view.rs | 13 +- crates/db_views/src/local_user_view.rs | 35 ++- crates/db_views/src/post_report_view.rs | 10 +- crates/db_views/src/post_view.rs | 12 +- .../src/private_message_report_view.rs | 13 +- crates/db_views/src/private_message_view.rs | 16 +- .../src/registration_application_view.rs | 16 +- crates/db_views/src/site_view.rs | 6 +- .../db_views_actor/src/comment_reply_view.rs | 13 +- .../src/community_block_view.rs | 9 +- .../src/community_follower_view.rs | 16 +- .../src/community_moderator_view.rs | 20 +- .../src/community_person_ban_view.rs | 6 +- crates/db_views_actor/src/community_view.rs | 8 +- .../db_views_actor/src/person_block_view.rs | 9 +- .../db_views_actor/src/person_mention_view.rs | 13 +- crates/db_views_actor/src/person_view.rs | 14 +- .../src/admin_purge_comment_view.rs | 9 +- .../src/admin_purge_community_view.rs | 9 +- .../src/admin_purge_person_view.rs | 9 +- .../src/admin_purge_post_view.rs | 9 +- .../src/mod_add_community_view.rs | 9 +- crates/db_views_moderator/src/mod_add_view.rs | 9 +- .../src/mod_ban_from_community_view.rs | 9 +- crates/db_views_moderator/src/mod_ban_view.rs | 9 +- .../src/mod_feature_post_view.rs | 9 +- .../src/mod_hide_community_view.rs | 9 +- .../src/mod_lock_post_view.rs | 9 +- .../src/mod_remove_comment_view.rs | 9 +- .../src/mod_remove_community_view.rs | 9 +- .../src/mod_remove_post_view.rs | 9 +- .../src/mod_transfer_community_view.rs | 9 +- crates/routes/src/feeds.rs | 10 +- src/code_migrations.rs | 43 ++-- 82 files changed, 1070 insertions(+), 711 deletions(-) diff --git a/crates/api_common/src/context.rs b/crates/api_common/src/context.rs index 42fa74964..2d2eb7814 100644 --- a/crates/api_common/src/context.rs +++ b/crates/api_common/src/context.rs @@ -28,7 +28,7 @@ impl LemmyContext { rate_limit_cell, } } - pub fn pool(&self) -> &DbPool { + pub fn pool(&self) -> impl GetConn { &self.pool } pub fn client(&self) -> &ClientWithMiddleware { diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index fd143ed90..aa42d4c58 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -24,7 +24,7 @@ use lemmy_db_schema::{ registration_application::RegistrationApplication, }, traits::{Crud, Readable}, - utils::DbPool, + utils::{DbPool, GetConn}, RegistrationMode, }; use lemmy_db_views::{comment_view::CommentQuery, structs::LocalUserView}; @@ -50,7 +50,7 @@ use url::{ParseError, Url}; #[tracing::instrument(skip_all)] pub async fn is_mod_or_admin( - pool: &DbPool, + mut pool: &mut impl GetConn, person_id: PersonId, community_id: CommunityId, ) -> Result<(), LemmyError> { @@ -63,7 +63,7 @@ pub async fn is_mod_or_admin( #[tracing::instrument(skip_all)] pub async fn is_mod_or_admin_opt( - pool: &DbPool, + mut pool: &mut impl GetConn, local_user_view: Option<&LocalUserView>, community_id: Option, ) -> Result<(), LemmyError> { @@ -101,7 +101,7 @@ pub fn is_top_mod( } #[tracing::instrument(skip_all)] -pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result { +pub async fn get_post(post_id: PostId, mut pool: &mut impl GetConn) -> Result { Post::read(pool, post_id) .await .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post")) @@ -111,7 +111,7 @@ pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result Result { let post_read_form = PostReadForm { post_id, person_id }; @@ -124,7 +124,7 @@ pub async fn mark_post_as_read( pub async fn mark_post_as_unread( person_id: PersonId, post_id: PostId, - pool: &DbPool, + mut pool: &mut impl GetConn, ) -> Result { let post_read_form = PostReadForm { post_id, person_id }; @@ -197,7 +197,7 @@ pub fn check_user_valid( pub async fn check_community_ban( person_id: PersonId, community_id: CommunityId, - pool: &DbPool, + mut pool: &mut impl GetConn, ) -> Result<(), LemmyError> { let is_banned = CommunityPersonBanView::get(pool, person_id, community_id) .await @@ -212,7 +212,7 @@ pub async fn check_community_ban( #[tracing::instrument(skip_all)] pub async fn check_community_deleted_or_removed( community_id: CommunityId, - pool: &DbPool, + mut pool: &mut impl GetConn, ) -> Result<(), LemmyError> { let community = Community::read(pool, community_id) .await @@ -236,7 +236,7 @@ pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> { pub async fn check_person_block( my_id: PersonId, potential_blocker_id: PersonId, - pool: &DbPool, + mut pool: &mut impl GetConn, ) -> Result<(), LemmyError> { let is_blocked = PersonBlock::read(pool, potential_blocker_id, my_id) .await @@ -270,7 +270,7 @@ pub fn check_private_instance( #[tracing::instrument(skip_all)] pub async fn build_federated_instances( local_site: &LocalSite, - pool: &DbPool, + mut pool: &mut impl GetConn, ) -> Result, LemmyError> { if local_site.federation_enabled { // TODO I hate that this requires 3 queries @@ -334,7 +334,7 @@ pub fn send_email_to_user( pub async fn send_password_reset_email( user: &LocalUserView, - pool: &DbPool, + mut pool: &mut impl GetConn, settings: &Settings, ) -> Result<(), LemmyError> { // Generate a random token @@ -358,7 +358,7 @@ pub async fn send_password_reset_email( pub async fn send_verification_email( user: &LocalUserView, new_email: &str, - pool: &DbPool, + mut pool: &mut impl GetConn, settings: &Settings, ) -> Result<(), LemmyError> { let form = EmailVerificationForm { @@ -449,7 +449,7 @@ pub fn send_application_approved_email( /// Send a new applicant email notification to all admins pub async fn send_new_applicant_email_to_admins( applicant_username: &str, - pool: &DbPool, + mut pool: &mut impl GetConn, settings: &Settings, ) -> Result<(), LemmyError> { // Collect the admins with emails @@ -474,7 +474,7 @@ pub async fn send_new_applicant_email_to_admins( pub async fn send_new_report_email_to_admins( reporter_username: &str, reported_username: &str, - pool: &DbPool, + mut pool: &mut impl GetConn, settings: &Settings, ) -> Result<(), LemmyError> { // Collect the admins with emails @@ -495,7 +495,7 @@ pub async fn send_new_report_email_to_admins( pub async fn check_registration_application( local_user_view: &LocalUserView, local_site: &LocalSite, - pool: &DbPool, + mut pool: &mut impl GetConn, ) -> Result<(), LemmyError> { if (local_site.registration_mode == RegistrationMode::RequireApplication || local_site.registration_mode == RegistrationMode::Closed) @@ -529,7 +529,7 @@ pub fn check_private_instance_and_federation_enabled( pub async fn purge_image_posts_for_person( banned_person_id: PersonId, - pool: &DbPool, + mut pool: &mut impl GetConn, settings: &Settings, client: &ClientWithMiddleware, ) -> Result<(), LemmyError> { @@ -552,7 +552,7 @@ pub async fn purge_image_posts_for_person( pub async fn purge_image_posts_for_community( banned_community_id: CommunityId, - pool: &DbPool, + mut pool: &mut impl GetConn, settings: &Settings, client: &ClientWithMiddleware, ) -> Result<(), LemmyError> { @@ -575,7 +575,7 @@ pub async fn purge_image_posts_for_community( pub async fn remove_user_data( banned_person_id: PersonId, - pool: &DbPool, + mut pool: &mut impl GetConn, settings: &Settings, client: &ClientWithMiddleware, ) -> Result<(), LemmyError> { @@ -659,7 +659,7 @@ pub async fn remove_user_data( pub async fn remove_user_data_in_community( community_id: CommunityId, banned_person_id: PersonId, - pool: &DbPool, + mut pool: &mut impl GetConn, ) -> Result<(), LemmyError> { // Posts Post::update_removed_for_creator(pool, banned_person_id, Some(community_id), true).await?; @@ -689,7 +689,7 @@ pub async fn remove_user_data_in_community( pub async fn delete_user_account( person_id: PersonId, - pool: &DbPool, + mut pool: &mut impl GetConn, settings: &Settings, client: &ClientWithMiddleware, ) -> Result<(), LemmyError> { diff --git a/crates/apub/src/activities/block/mod.rs b/crates/apub/src/activities/block/mod.rs index a791ea40e..a8ec80b2f 100644 --- a/crates/apub/src/activities/block/mod.rs +++ b/crates/apub/src/activities/block/mod.rs @@ -21,7 +21,7 @@ use lemmy_api_common::{ use lemmy_db_schema::{ source::{community::Community, person::Person, site::Site}, traits::Crud, - utils::DbPool, + utils::{DbPool, GetConn}, }; use lemmy_db_views::structs::SiteView; use lemmy_utils::{error::LemmyError, utils::time::naive_from_unix}; @@ -118,7 +118,10 @@ impl SiteOrCommunity { } } -async fn generate_cc(target: &SiteOrCommunity, pool: &DbPool) -> Result, LemmyError> { +async fn generate_cc( + target: &SiteOrCommunity, + mut pool: &mut impl GetConn, +) -> Result, LemmyError> { Ok(match target { SiteOrCommunity::Site(_) => Site::read_remote_sites(pool) .await? diff --git a/crates/apub/src/api/resolve_object.rs b/crates/apub/src/api/resolve_object.rs index 09689def1..8377421ec 100644 --- a/crates/apub/src/api/resolve_object.rs +++ b/crates/apub/src/api/resolve_object.rs @@ -33,7 +33,7 @@ pub async fn resolve_object( async fn convert_response( object: SearchableObjects, user_id: PersonId, - pool: &DbPool, + mut pool: &mut impl GetConn, ) -> Result, LemmyError> { use SearchableObjects::*; let removed_or_deleted; diff --git a/crates/apub/src/lib.rs b/crates/apub/src/lib.rs index a5bc41d1f..0fc4ac20a 100644 --- a/crates/apub/src/lib.rs +++ b/crates/apub/src/lib.rs @@ -9,7 +9,7 @@ use lemmy_db_schema::{ local_site::LocalSite, }, traits::Crud, - utils::DbPool, + utils::{DbPool, GetConn}, }; use lemmy_utils::{error::LemmyError, settings::structs::Settings}; use once_cell::sync::Lazy; @@ -98,7 +98,7 @@ pub(crate) struct LocalSiteData { } pub(crate) async fn fetch_local_site_data( - pool: &DbPool, + mut pool: &mut impl GetConn, ) -> Result { // LocalSite may be missing let local_site = LocalSite::read(pool).await.ok(); diff --git a/crates/apub/src/mentions.rs b/crates/apub/src/mentions.rs index 088f84d0d..f49f88273 100644 --- a/crates/apub/src/mentions.rs +++ b/crates/apub/src/mentions.rs @@ -9,7 +9,7 @@ use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::{ source::{comment::Comment, person::Person, post::Post}, traits::Crud, - utils::DbPool, + utils::{DbPool, GetConn}, }; use lemmy_utils::{error::LemmyError, utils::mention::scrape_text_for_mentions}; use serde::{Deserialize, Serialize}; @@ -92,7 +92,7 @@ pub async fn collect_non_local_mentions( /// top-level comment, the creator of the post, otherwise the creator of the parent comment. #[tracing::instrument(skip(pool, comment))] async fn get_comment_parent_creator( - pool: &DbPool, + mut pool: &mut impl GetConn, comment: &Comment, ) -> Result { let parent_creator_id = if let Some(parent_comment_id) = comment.parent_comment_id() { diff --git a/crates/apub/src/objects/instance.rs b/crates/apub/src/objects/instance.rs index 6cd27fbbd..097cefb0b 100644 --- a/crates/apub/src/objects/instance.rs +++ b/crates/apub/src/objects/instance.rs @@ -195,7 +195,9 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object + C } } -pub(crate) async fn remote_instance_inboxes(pool: &DbPool) -> Result, LemmyError> { +pub(crate) async fn remote_instance_inboxes( + mut pool: &mut impl GetConn, +) -> Result, LemmyError> { Ok( Site::read_remote_sites(pool) .await? diff --git a/crates/apub/src/protocol/objects/mod.rs b/crates/apub/src/protocol/objects/mod.rs index f35140a9b..791ff6e0b 100644 --- a/crates/apub/src/protocol/objects/mod.rs +++ b/crates/apub/src/protocol/objects/mod.rs @@ -2,7 +2,7 @@ use lemmy_db_schema::{ impls::actor_language::UNDETERMINED_ID, newtypes::LanguageId, source::language::Language, - utils::DbPool, + utils::{DbPool, GetConn}, }; use lemmy_utils::error::LemmyError; use serde::{Deserialize, Serialize}; @@ -33,7 +33,7 @@ pub(crate) struct LanguageTag { impl LanguageTag { pub(crate) async fn new_single( lang: LanguageId, - pool: &DbPool, + mut pool: &mut impl GetConn, ) -> Result, LemmyError> { let lang = Language::read_from_id(pool, lang).await?; @@ -50,7 +50,7 @@ impl LanguageTag { pub(crate) async fn new_multiple( lang_ids: Vec, - pool: &DbPool, + mut pool: &mut impl GetConn, ) -> Result, LemmyError> { let mut langs = Vec::::new(); @@ -70,7 +70,7 @@ impl LanguageTag { pub(crate) async fn to_language_id_single( lang: Option, - pool: &DbPool, + mut pool: &mut impl GetConn, ) -> Result, LemmyError> { let identifier = lang.map(|l| l.identifier); let language = Language::read_id_from_code(pool, identifier.as_deref()).await?; @@ -80,7 +80,7 @@ impl LanguageTag { pub(crate) async fn to_language_id_multiple( langs: Vec, - pool: &DbPool, + mut pool: &mut impl GetConn, ) -> Result, LemmyError> { let mut language_ids = Vec::new(); diff --git a/crates/db_schema/src/aggregates/comment_aggregates.rs b/crates/db_schema/src/aggregates/comment_aggregates.rs index 5a5550a2e..77cd8f0c2 100644 --- a/crates/db_schema/src/aggregates/comment_aggregates.rs +++ b/crates/db_schema/src/aggregates/comment_aggregates.rs @@ -2,22 +2,25 @@ use crate::{ aggregates::structs::CommentAggregates, newtypes::CommentId, schema::comment_aggregates, - utils::{functions::hot_rank, get_conn, DbPool}, + utils::{functions::hot_rank, DbPool, GetConn}, }; use diesel::{result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; impl CommentAggregates { - pub async fn read(pool: &DbPool, comment_id: CommentId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read(mut pool: &mut impl GetConn, comment_id: CommentId) -> Result { + let conn = &mut *pool.get_conn().await?; comment_aggregates::table .filter(comment_aggregates::comment_id.eq(comment_id)) .first::(conn) .await } - pub async fn update_hot_rank(pool: &DbPool, comment_id: CommentId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn update_hot_rank( + mut pool: &mut impl GetConn, + comment_id: CommentId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::update(comment_aggregates::table) .filter(comment_aggregates::comment_id.eq(comment_id)) diff --git a/crates/db_schema/src/aggregates/community_aggregates.rs b/crates/db_schema/src/aggregates/community_aggregates.rs index 2c2eaa781..b667bfaeb 100644 --- a/crates/db_schema/src/aggregates/community_aggregates.rs +++ b/crates/db_schema/src/aggregates/community_aggregates.rs @@ -2,14 +2,14 @@ use crate::{ aggregates::structs::CommunityAggregates, newtypes::CommunityId, schema::community_aggregates, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; impl CommunityAggregates { - pub async fn read(pool: &DbPool, community_id: CommunityId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read(mut pool: &mut impl GetConn, community_id: CommunityId) -> Result { + let conn = &mut *pool.get_conn().await?; community_aggregates::table .filter(community_aggregates::community_id.eq(community_id)) .first::(conn) diff --git a/crates/db_schema/src/aggregates/person_aggregates.rs b/crates/db_schema/src/aggregates/person_aggregates.rs index 295f1bfbb..c900973e0 100644 --- a/crates/db_schema/src/aggregates/person_aggregates.rs +++ b/crates/db_schema/src/aggregates/person_aggregates.rs @@ -2,14 +2,14 @@ use crate::{ aggregates::structs::PersonAggregates, newtypes::PersonId, schema::person_aggregates, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; impl PersonAggregates { - pub async fn read(pool: &DbPool, person_id: PersonId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read(mut pool: &mut impl GetConn, person_id: PersonId) -> Result { + let conn = &mut *pool.get_conn().await?; person_aggregates::table .filter(person_aggregates::person_id.eq(person_id)) .first::(conn) diff --git a/crates/db_schema/src/aggregates/person_post_aggregates.rs b/crates/db_schema/src/aggregates/person_post_aggregates.rs index 5fe1aacff..bcec04d03 100644 --- a/crates/db_schema/src/aggregates/person_post_aggregates.rs +++ b/crates/db_schema/src/aggregates/person_post_aggregates.rs @@ -3,14 +3,17 @@ use crate::{ diesel::BoolExpressionMethods, newtypes::{PersonId, PostId}, schema::person_post_aggregates::dsl::{person_id, person_post_aggregates, post_id}, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; impl PersonPostAggregates { - pub async fn upsert(pool: &DbPool, form: &PersonPostAggregatesForm) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn upsert( + mut pool: &mut impl GetConn, + form: &PersonPostAggregatesForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(person_post_aggregates) .values(form) .on_conflict((person_id, post_id)) @@ -19,8 +22,12 @@ impl PersonPostAggregates { .get_result::(conn) .await } - pub async fn read(pool: &DbPool, person_id_: PersonId, post_id_: PostId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read( + mut pool: &mut impl GetConn, + person_id_: PersonId, + post_id_: PostId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; person_post_aggregates .filter(post_id.eq(post_id_).and(person_id.eq(person_id_))) .first::(conn) diff --git a/crates/db_schema/src/aggregates/post_aggregates.rs b/crates/db_schema/src/aggregates/post_aggregates.rs index 176f694a7..dc09ced9f 100644 --- a/crates/db_schema/src/aggregates/post_aggregates.rs +++ b/crates/db_schema/src/aggregates/post_aggregates.rs @@ -2,22 +2,25 @@ use crate::{ aggregates::structs::PostAggregates, newtypes::PostId, schema::post_aggregates, - utils::{functions::hot_rank, get_conn, DbPool}, + utils::{functions::hot_rank, DbPool, GetConn}, }; use diesel::{result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; impl PostAggregates { - pub async fn read(pool: &DbPool, post_id: PostId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read(mut pool: &mut impl GetConn, post_id: PostId) -> Result { + let conn = &mut *pool.get_conn().await?; post_aggregates::table .filter(post_aggregates::post_id.eq(post_id)) .first::(conn) .await } - pub async fn update_hot_rank(pool: &DbPool, post_id: PostId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn update_hot_rank( + mut pool: &mut impl GetConn, + post_id: PostId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::update(post_aggregates::table) .filter(post_aggregates::post_id.eq(post_id)) diff --git a/crates/db_schema/src/aggregates/site_aggregates.rs b/crates/db_schema/src/aggregates/site_aggregates.rs index 719beb8f7..359507cf9 100644 --- a/crates/db_schema/src/aggregates/site_aggregates.rs +++ b/crates/db_schema/src/aggregates/site_aggregates.rs @@ -1,14 +1,14 @@ use crate::{ aggregates::structs::SiteAggregates, schema::site_aggregates, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::result::Error; use diesel_async::RunQueryDsl; impl SiteAggregates { - pub async fn read(pool: &DbPool) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read(mut pool: &mut impl GetConn) -> Result { + let conn = &mut *pool.get_conn().await?; site_aggregates::table.first::(conn).await } } diff --git a/crates/db_schema/src/impls/activity.rs b/crates/db_schema/src/impls/activity.rs index 9187e736c..055d074df 100644 --- a/crates/db_schema/src/impls/activity.rs +++ b/crates/db_schema/src/impls/activity.rs @@ -3,7 +3,7 @@ use crate::{ schema::activity::dsl::{activity, ap_id}, source::activity::{Activity, ActivityInsertForm, ActivityUpdateForm}, traits::Crud, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; @@ -13,13 +13,16 @@ impl Crud for Activity { type InsertForm = ActivityInsertForm; type UpdateForm = ActivityUpdateForm; type IdType = i32; - async fn read(pool: &DbPool, activity_id: i32) -> Result { - let conn = &mut get_conn(pool).await?; + async fn read(mut pool: &mut impl GetConn, activity_id: i32) -> Result { + let conn = &mut *pool.get_conn().await?; activity.find(activity_id).first::(conn).await } - async fn create(pool: &DbPool, new_activity: &Self::InsertForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn create( + mut pool: &mut impl GetConn, + new_activity: &Self::InsertForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(activity) .values(new_activity) .get_result::(conn) @@ -27,18 +30,18 @@ impl Crud for Activity { } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, activity_id: i32, new_activity: &Self::UpdateForm, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(activity.find(activity_id)) .set(new_activity) .get_result::(conn) .await } - async fn delete(pool: &DbPool, activity_id: i32) -> Result { - let conn = &mut get_conn(pool).await?; + async fn delete(mut pool: &mut impl GetConn, activity_id: i32) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete(activity.find(activity_id)) .execute(conn) .await @@ -46,8 +49,11 @@ impl Crud for Activity { } impl Activity { - pub async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read_from_apub_id( + mut pool: &mut impl GetConn, + object_id: &DbUrl, + ) -> Result { + let conn = &mut *pool.get_conn().await?; activity .filter(ap_id.eq(object_id)) .first::(conn) diff --git a/crates/db_schema/src/impls/actor_language.rs b/crates/db_schema/src/impls/actor_language.rs index dbb9c70fe..a3e0d7419 100644 --- a/crates/db_schema/src/impls/actor_language.rs +++ b/crates/db_schema/src/impls/actor_language.rs @@ -14,7 +14,7 @@ use crate::{ language::Language, site::Site, }, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{ delete, @@ -37,7 +37,7 @@ pub const UNDETERMINED_ID: LanguageId = LanguageId(0); impl LocalUserLanguage { pub async fn read( - pool: &DbPool, + mut pool: &mut impl GetConn, for_local_user_id: LocalUserId, ) -> Result, Error> { use crate::schema::local_user_language::dsl::{ @@ -45,7 +45,7 @@ impl LocalUserLanguage { local_user_id, local_user_language, }; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; conn .build_transaction() @@ -67,11 +67,11 @@ impl LocalUserLanguage { /// /// If no language_id vector is given, it will show all languages pub async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, language_ids: Vec, for_local_user_id: LocalUserId, ) -> Result<(), Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let mut lang_ids = convert_update_languages(conn, language_ids).await?; // No need to update if languages are unchanged @@ -118,8 +118,8 @@ impl LocalUserLanguage { } impl SiteLanguage { - pub async fn read_local_raw(pool: &DbPool) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn read_local_raw(mut pool: &mut impl GetConn) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; site::table .inner_join(local_site::table) .inner_join(site_language::table) @@ -130,7 +130,7 @@ impl SiteLanguage { } async fn read_raw( - conn: &mut PooledConnection, + conn: &mut AsyncPgConnection, for_site_id: SiteId, ) -> Result, Error> { site_language::table @@ -141,19 +141,22 @@ impl SiteLanguage { .await } - pub async fn read(pool: &DbPool, for_site_id: SiteId) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn read( + mut pool: &mut impl GetConn, + for_site_id: SiteId, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let langs = Self::read_raw(conn, for_site_id).await?; convert_read_languages(conn, langs).await } pub async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, language_ids: Vec, site: &Site, ) -> Result<(), Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let for_site_id = site.id; let instance_id = site.instance_id; let lang_ids = convert_update_languages(conn, language_ids).await?; @@ -198,12 +201,12 @@ impl SiteLanguage { impl CommunityLanguage { /// Returns true if the given language is one of configured languages for given community pub async fn is_allowed_community_language( - pool: &DbPool, + mut pool: &mut impl GetConn, for_language_id: Option, for_community_id: CommunityId, ) -> Result<(), LemmyError> { use crate::schema::community_language::dsl::{community_id, community_language, language_id}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; if let Some(for_language_id) = for_language_id { let is_allowed = select(exists( @@ -255,7 +258,7 @@ impl CommunityLanguage { } async fn read_raw( - conn: &mut PooledConnection, + conn: &mut AsyncPgConnection, for_community_id: CommunityId, ) -> Result, Error> { use crate::schema::community_language::dsl::{community_id, community_language, language_id}; @@ -268,20 +271,20 @@ impl CommunityLanguage { } pub async fn read( - pool: &DbPool, + mut pool: &mut impl GetConn, for_community_id: CommunityId, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let langs = Self::read_raw(conn, for_community_id).await?; convert_read_languages(conn, langs).await } pub async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, mut language_ids: Vec, for_community_id: CommunityId, ) -> Result<(), Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; if language_ids.is_empty() { language_ids = SiteLanguage::read_local_raw(pool).await?; } @@ -321,12 +324,12 @@ impl CommunityLanguage { } pub async fn default_post_language( - pool: &DbPool, + mut pool: &mut impl GetConn, community_id: CommunityId, local_user_id: LocalUserId, ) -> Result, Error> { use crate::schema::{community_language::dsl as cl, local_user_language::dsl as ul}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let mut intersection = ul::local_user_language .inner_join(cl::community_language.on(ul::language_id.eq(cl::language_id))) .filter(ul::local_user_id.eq(local_user_id)) @@ -396,9 +399,9 @@ mod tests { convert_read_languages, convert_update_languages, default_post_language, - get_conn, CommunityLanguage, DbPool, + GetConn, Language, LanguageId, LocalUserLanguage, @@ -419,7 +422,7 @@ mod tests { }; use serial_test::serial; - async fn test_langs1(pool: &DbPool) -> Vec { + async fn test_langs1(mut pool: &mut impl GetConn) -> Vec { vec![ Language::read_id_from_code(pool, Some("en")) .await @@ -435,7 +438,7 @@ mod tests { .unwrap(), ] } - async fn test_langs2(pool: &DbPool) -> Vec { + async fn test_langs2(mut pool: &mut impl GetConn) -> Vec { vec![ Language::read_id_from_code(pool, Some("fi")) .await @@ -448,7 +451,7 @@ mod tests { ] } - async fn create_test_site(pool: &DbPool) -> (Site, Instance) { + async fn create_test_site(mut pool: &mut impl GetConn) -> (Site, Instance) { let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()) .await .unwrap(); diff --git a/crates/db_schema/src/impls/captcha_answer.rs b/crates/db_schema/src/impls/captcha_answer.rs index de5fac65e..50491569c 100644 --- a/crates/db_schema/src/impls/captcha_answer.rs +++ b/crates/db_schema/src/impls/captcha_answer.rs @@ -1,7 +1,7 @@ use crate::{ schema::captcha_answer::dsl::{answer, captcha_answer, uuid}, source::captcha_answer::{CaptchaAnswer, CaptchaAnswerForm, CheckCaptchaAnswer}, - utils::{functions::lower, get_conn, DbPool}, + utils::{functions::lower, DbPool, GetConn}, }; use diesel::{ delete, @@ -15,8 +15,11 @@ use diesel::{ use diesel_async::RunQueryDsl; impl CaptchaAnswer { - pub async fn insert(pool: &DbPool, captcha: &CaptchaAnswerForm) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn insert( + mut pool: &mut impl GetConn, + captcha: &CaptchaAnswerForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(captcha_answer) .values(captcha) @@ -24,8 +27,11 @@ impl CaptchaAnswer { .await } - pub async fn check_captcha(pool: &DbPool, to_check: CheckCaptchaAnswer) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn check_captcha( + mut pool: &mut impl GetConn, + to_check: CheckCaptchaAnswer, + ) -> Result { + let conn = &mut *pool.get_conn().await?; // fetch requested captcha let captcha_exists = select(exists( diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index ea66347db..a4289532a 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -11,7 +11,7 @@ use crate::{ CommentUpdateForm, }, traits::{Crud, Likeable, Saveable}, - utils::{get_conn, naive_now, DbPool, DELETED_REPLACEMENT_TEXT}, + utils::{naive_now, DbPool, GetConn, DELETED_REPLACEMENT_TEXT}, }; use diesel::{ dsl::{insert_into, sql_query}, @@ -25,10 +25,10 @@ use url::Url; impl Comment { pub async fn permadelete_for_creator( - pool: &DbPool, + mut pool: &mut impl GetConn, for_creator_id: PersonId, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(comment.filter(creator_id.eq(for_creator_id))) .set(( @@ -41,11 +41,11 @@ impl Comment { } pub async fn update_removed_for_creator( - pool: &DbPool, + mut pool: &mut impl GetConn, for_creator_id: PersonId, new_removed: bool, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(comment.filter(creator_id.eq(for_creator_id))) .set((removed.eq(new_removed), updated.eq(naive_now()))) .get_results::(conn) @@ -53,11 +53,11 @@ impl Comment { } pub async fn create( - pool: &DbPool, + mut pool: &mut impl GetConn, comment_form: &CommentInsertForm, parent_path: Option<&Ltree>, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; // Insert, to get the id let inserted_comment = insert_into(comment) @@ -123,8 +123,11 @@ where ca.comment_id = c.id" inserted_comment } } - pub async fn read_from_apub_id(pool: &DbPool, object_id: Url) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn read_from_apub_id( + mut pool: &mut impl GetConn, + object_id: Url, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let object_id: DbUrl = object_id.into(); Ok( comment @@ -153,27 +156,30 @@ impl Crud for Comment { type InsertForm = CommentInsertForm; type UpdateForm = CommentUpdateForm; type IdType = CommentId; - async fn read(pool: &DbPool, comment_id: CommentId) -> Result { - let conn = &mut get_conn(pool).await?; + async fn read(mut pool: &mut impl GetConn, comment_id: CommentId) -> Result { + let conn = &mut *pool.get_conn().await?; comment.find(comment_id).first::(conn).await } - async fn delete(pool: &DbPool, comment_id: CommentId) -> Result { - let conn = &mut get_conn(pool).await?; + async fn delete(mut pool: &mut impl GetConn, comment_id: CommentId) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete(comment.find(comment_id)).execute(conn).await } /// This is unimplemented, use [[Comment::create]] - async fn create(_pool: &DbPool, _comment_form: &Self::InsertForm) -> Result { + async fn create( + _pool: &mut impl GetConn, + _comment_form: &Self::InsertForm, + ) -> Result { unimplemented!(); } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, comment_id: CommentId, comment_form: &Self::UpdateForm, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(comment.find(comment_id)) .set(comment_form) .get_result::(conn) @@ -185,9 +191,12 @@ impl Crud for Comment { impl Likeable for CommentLike { type Form = CommentLikeForm; type IdType = CommentId; - async fn like(pool: &DbPool, comment_like_form: &CommentLikeForm) -> Result { + async fn like( + mut pool: &mut impl GetConn, + comment_like_form: &CommentLikeForm, + ) -> Result { use crate::schema::comment_like::dsl::{comment_id, comment_like, person_id}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(comment_like) .values(comment_like_form) .on_conflict((comment_id, person_id)) @@ -197,12 +206,12 @@ impl Likeable for CommentLike { .await } async fn remove( - pool: &DbPool, + mut pool: &mut impl GetConn, person_id_: PersonId, comment_id_: CommentId, ) -> Result { use crate::schema::comment_like::dsl::{comment_id, comment_like, person_id}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::delete( comment_like .filter(comment_id.eq(comment_id_)) @@ -216,9 +225,12 @@ impl Likeable for CommentLike { #[async_trait] impl Saveable for CommentSaved { type Form = CommentSavedForm; - async fn save(pool: &DbPool, comment_saved_form: &CommentSavedForm) -> Result { + async fn save( + mut pool: &mut impl GetConn, + comment_saved_form: &CommentSavedForm, + ) -> Result { use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(comment_saved) .values(comment_saved_form) .on_conflict((comment_id, person_id)) @@ -227,9 +239,12 @@ impl Saveable for CommentSaved { .get_result::(conn) .await } - async fn unsave(pool: &DbPool, comment_saved_form: &CommentSavedForm) -> Result { + async fn unsave( + mut pool: &mut impl GetConn, + comment_saved_form: &CommentSavedForm, + ) -> Result { use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::delete( comment_saved .filter(comment_id.eq(comment_saved_form.comment_id)) diff --git a/crates/db_schema/src/impls/comment_reply.rs b/crates/db_schema/src/impls/comment_reply.rs index 2489c982f..309cc1763 100644 --- a/crates/db_schema/src/impls/comment_reply.rs +++ b/crates/db_schema/src/impls/comment_reply.rs @@ -3,7 +3,7 @@ use crate::{ schema::comment_reply::dsl::{comment_id, comment_reply, read, recipient_id}, source::comment_reply::{CommentReply, CommentReplyInsertForm, CommentReplyUpdateForm}, traits::Crud, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; @@ -13,16 +13,22 @@ impl Crud for CommentReply { type InsertForm = CommentReplyInsertForm; type UpdateForm = CommentReplyUpdateForm; type IdType = CommentReplyId; - async fn read(pool: &DbPool, comment_reply_id: CommentReplyId) -> Result { - let conn = &mut get_conn(pool).await?; + async fn read( + mut pool: &mut impl GetConn, + comment_reply_id: CommentReplyId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; comment_reply .find(comment_reply_id) .first::(conn) .await } - async fn create(pool: &DbPool, comment_reply_form: &Self::InsertForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn create( + mut pool: &mut impl GetConn, + comment_reply_form: &Self::InsertForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; // since the return here isnt utilized, we dont need to do an update // but get_result doesnt return the existing row here @@ -36,11 +42,11 @@ impl Crud for CommentReply { } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, comment_reply_id: CommentReplyId, comment_reply_form: &Self::UpdateForm, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(comment_reply.find(comment_reply_id)) .set(comment_reply_form) .get_result::(conn) @@ -50,10 +56,10 @@ impl Crud for CommentReply { impl CommentReply { pub async fn mark_all_as_read( - pool: &DbPool, + mut pool: &mut impl GetConn, for_recipient_id: PersonId, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update( comment_reply .filter(recipient_id.eq(for_recipient_id)) @@ -64,8 +70,11 @@ impl CommentReply { .await } - pub async fn read_by_comment(pool: &DbPool, for_comment_id: CommentId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read_by_comment( + mut pool: &mut impl GetConn, + for_comment_id: CommentId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; comment_reply .filter(comment_id.eq(for_comment_id)) .first::(conn) diff --git a/crates/db_schema/src/impls/comment_report.rs b/crates/db_schema/src/impls/comment_report.rs index 18cf83a72..9741c91b3 100644 --- a/crates/db_schema/src/impls/comment_report.rs +++ b/crates/db_schema/src/impls/comment_report.rs @@ -3,7 +3,7 @@ use crate::{ schema::comment_report::dsl::{comment_report, resolved, resolver_id, updated}, source::comment_report::{CommentReport, CommentReportForm}, traits::Reportable, - utils::{get_conn, naive_now, DbPool}, + utils::{naive_now, DbPool, GetConn}, }; use diesel::{ dsl::{insert_into, update}, @@ -21,8 +21,11 @@ impl Reportable for CommentReport { /// /// * `conn` - the postgres connection /// * `comment_report_form` - the filled CommentReportForm to insert - async fn report(pool: &DbPool, comment_report_form: &CommentReportForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn report( + mut pool: &mut impl GetConn, + comment_report_form: &CommentReportForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(comment_report) .values(comment_report_form) .get_result::(conn) @@ -35,11 +38,11 @@ impl Reportable for CommentReport { /// * `report_id` - the id of the report to resolve /// * `by_resolver_id` - the id of the user resolving the report async fn resolve( - pool: &DbPool, + mut pool: &mut impl GetConn, report_id_: Self::IdType, by_resolver_id: PersonId, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; update(comment_report.find(report_id_)) .set(( resolved.eq(true), @@ -56,11 +59,11 @@ impl Reportable for CommentReport { /// * `report_id` - the id of the report to unresolve /// * `by_resolver_id` - the id of the user unresolving the report async fn unresolve( - pool: &DbPool, + mut pool: &mut impl GetConn, report_id_: Self::IdType, by_resolver_id: PersonId, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; update(comment_report.find(report_id_)) .set(( resolved.eq(false), diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index ad9e6d47d..67d2b9c25 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -16,7 +16,7 @@ use crate::{ }, }, traits::{ApubActor, Bannable, Crud, Followable, Joinable}, - utils::{functions::lower, get_conn, DbPool}, + utils::{functions::lower, DbPool, GetConn}, SubscribedType, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; @@ -27,23 +27,23 @@ impl Crud for Community { type InsertForm = CommunityInsertForm; type UpdateForm = CommunityUpdateForm; type IdType = CommunityId; - async fn read(pool: &DbPool, community_id: CommunityId) -> Result { - let conn = &mut get_conn(pool).await?; + async fn read(mut pool: &mut impl GetConn, community_id: CommunityId) -> Result { + let conn = &mut *pool.get_conn().await?; community::table .find(community_id) .first::(conn) .await } - async fn delete(pool: &DbPool, community_id: CommunityId) -> Result { - let conn = &mut get_conn(pool).await?; + async fn delete(mut pool: &mut impl GetConn, community_id: CommunityId) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete(community::table.find(community_id)) .execute(conn) .await } - async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { + let conn = &mut *pool.get_conn().await?; let is_new_community = match &form.actor_id { Some(id) => Community::read_from_apub_id(pool, id).await?.is_none(), None => true, @@ -67,11 +67,11 @@ impl Crud for Community { } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, community_id: CommunityId, form: &Self::UpdateForm, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(community::table.find(community_id)) .set(form) .get_result::(conn) @@ -83,11 +83,11 @@ impl Crud for Community { impl Joinable for CommunityModerator { type Form = CommunityModeratorForm; async fn join( - pool: &DbPool, + mut pool: &mut impl GetConn, community_moderator_form: &CommunityModeratorForm, ) -> Result { use crate::schema::community_moderator::dsl::community_moderator; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(community_moderator) .values(community_moderator_form) .get_result::(conn) @@ -95,11 +95,11 @@ impl Joinable for CommunityModerator { } async fn leave( - pool: &DbPool, + mut pool: &mut impl GetConn, community_moderator_form: &CommunityModeratorForm, ) -> Result { use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::delete( community_moderator .filter(community_id.eq(community_moderator_form.community_id)) @@ -118,12 +118,12 @@ pub enum CollectionType { impl Community { /// Get the community which has a given moderators or featured url, also return the collection type pub async fn get_by_collection_url( - pool: &DbPool, + mut pool: &mut impl GetConn, url: &DbUrl, ) -> Result<(Community, CollectionType), Error> { use crate::schema::community::dsl::{featured_url, moderators_url}; use CollectionType::*; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let res = community::table .filter(moderators_url.eq(url)) .first::(conn) @@ -144,11 +144,11 @@ impl Community { impl CommunityModerator { pub async fn delete_for_community( - pool: &DbPool, + mut pool: &mut impl GetConn, for_community_id: CommunityId, ) -> Result { use crate::schema::community_moderator::dsl::{community_id, community_moderator}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::delete(community_moderator.filter(community_id.eq(for_community_id))) .execute(conn) @@ -156,22 +156,22 @@ impl CommunityModerator { } pub async fn leave_all_communities( - pool: &DbPool, + mut pool: &mut impl GetConn, for_person_id: PersonId, ) -> Result { use crate::schema::community_moderator::dsl::{community_moderator, person_id}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::delete(community_moderator.filter(person_id.eq(for_person_id))) .execute(conn) .await } pub async fn get_person_moderated_communities( - pool: &DbPool, + mut pool: &mut impl GetConn, for_person_id: PersonId, ) -> Result, Error> { use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; community_moderator .filter(person_id.eq(for_person_id)) .select(community_id) @@ -184,11 +184,11 @@ impl CommunityModerator { impl Bannable for CommunityPersonBan { type Form = CommunityPersonBanForm; async fn ban( - pool: &DbPool, + mut pool: &mut impl GetConn, community_person_ban_form: &CommunityPersonBanForm, ) -> Result { use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(community_person_ban) .values(community_person_ban_form) .on_conflict((community_id, person_id)) @@ -199,11 +199,11 @@ impl Bannable for CommunityPersonBan { } async fn unban( - pool: &DbPool, + mut pool: &mut impl GetConn, community_person_ban_form: &CommunityPersonBanForm, ) -> Result { use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::delete( community_person_ban .filter(community_id.eq(community_person_ban_form.community_id)) @@ -233,9 +233,12 @@ impl CommunityFollower { #[async_trait] impl Followable for CommunityFollower { type Form = CommunityFollowerForm; - async fn follow(pool: &DbPool, form: &CommunityFollowerForm) -> Result { + async fn follow( + mut pool: &mut impl GetConn, + form: &CommunityFollowerForm, + ) -> Result { use crate::schema::community_follower::dsl::{community_follower, community_id, person_id}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(community_follower) .values(form) .on_conflict((community_id, person_id)) @@ -245,7 +248,7 @@ impl Followable for CommunityFollower { .await } async fn follow_accepted( - pool: &DbPool, + mut pool: &mut impl GetConn, community_id_: CommunityId, person_id_: PersonId, ) -> Result { @@ -255,7 +258,7 @@ impl Followable for CommunityFollower { pending, person_id, }; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update( community_follower .filter(community_id.eq(community_id_)) @@ -265,9 +268,12 @@ impl Followable for CommunityFollower { .get_result::(conn) .await } - async fn unfollow(pool: &DbPool, form: &CommunityFollowerForm) -> Result { + async fn unfollow( + mut pool: &mut impl GetConn, + form: &CommunityFollowerForm, + ) -> Result { use crate::schema::community_follower::dsl::{community_follower, community_id, person_id}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::delete( community_follower .filter(community_id.eq(&form.community_id)) @@ -280,8 +286,11 @@ impl Followable for CommunityFollower { #[async_trait] impl ApubActor for Community { - async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + async fn read_from_apub_id( + mut pool: &mut impl GetConn, + object_id: &DbUrl, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; Ok( community::table .filter(community::actor_id.eq(object_id)) @@ -293,11 +302,11 @@ impl ApubActor for Community { } async fn read_from_name( - pool: &DbPool, + mut pool: &mut impl GetConn, community_name: &str, include_deleted: bool, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let mut q = community::table .into_boxed() .filter(community::local.eq(true)) @@ -311,11 +320,11 @@ impl ApubActor for Community { } async fn read_from_name_and_domain( - pool: &DbPool, + mut pool: &mut impl GetConn, community_name: &str, for_domain: &str, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; community::table .inner_join(instance::table) .filter(lower(community::name).eq(community_name.to_lowercase())) diff --git a/crates/db_schema/src/impls/community_block.rs b/crates/db_schema/src/impls/community_block.rs index c1f35e625..56054e236 100644 --- a/crates/db_schema/src/impls/community_block.rs +++ b/crates/db_schema/src/impls/community_block.rs @@ -2,7 +2,7 @@ use crate::{ schema::community_block::dsl::{community_block, community_id, person_id}, source::community_block::{CommunityBlock, CommunityBlockForm}, traits::Blockable, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; @@ -10,8 +10,11 @@ use diesel_async::RunQueryDsl; #[async_trait] impl Blockable for CommunityBlock { type Form = CommunityBlockForm; - async fn block(pool: &DbPool, community_block_form: &Self::Form) -> Result { - let conn = &mut get_conn(pool).await?; + async fn block( + mut pool: &mut impl GetConn, + community_block_form: &Self::Form, + ) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(community_block) .values(community_block_form) .on_conflict((person_id, community_id)) @@ -20,8 +23,11 @@ impl Blockable for CommunityBlock { .get_result::(conn) .await } - async fn unblock(pool: &DbPool, community_block_form: &Self::Form) -> Result { - let conn = &mut get_conn(pool).await?; + async fn unblock( + mut pool: &mut impl GetConn, + community_block_form: &Self::Form, + ) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete( community_block .filter(person_id.eq(community_block_form.person_id)) diff --git a/crates/db_schema/src/impls/custom_emoji.rs b/crates/db_schema/src/impls/custom_emoji.rs index cce35dfc7..081f2ac5a 100644 --- a/crates/db_schema/src/impls/custom_emoji.rs +++ b/crates/db_schema/src/impls/custom_emoji.rs @@ -8,32 +8,38 @@ use crate::{ custom_emoji::{CustomEmoji, CustomEmojiInsertForm, CustomEmojiUpdateForm}, custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm}, }, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; impl CustomEmoji { - pub async fn create(pool: &DbPool, form: &CustomEmojiInsertForm) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn create( + mut pool: &mut impl GetConn, + form: &CustomEmojiInsertForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(custom_emoji) .values(form) .get_result::(conn) .await } pub async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, emoji_id: CustomEmojiId, form: &CustomEmojiUpdateForm, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(custom_emoji.find(emoji_id)) .set(form) .get_result::(conn) .await } - pub async fn delete(pool: &DbPool, emoji_id: CustomEmojiId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn delete( + mut pool: &mut impl GetConn, + emoji_id: CustomEmojiId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete(custom_emoji.find(emoji_id)) .execute(conn) .await @@ -42,17 +48,20 @@ impl CustomEmoji { impl CustomEmojiKeyword { pub async fn create( - pool: &DbPool, + mut pool: &mut impl GetConn, form: Vec, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(custom_emoji_keyword) .values(form) .get_results::(conn) .await } - pub async fn delete(pool: &DbPool, emoji_id: CustomEmojiId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn delete( + mut pool: &mut impl GetConn, + emoji_id: CustomEmojiId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete(custom_emoji_keyword.filter(custom_emoji_id.eq(emoji_id))) .execute(conn) .await diff --git a/crates/db_schema/src/impls/email_verification.rs b/crates/db_schema/src/impls/email_verification.rs index af19bbba0..2d58404e0 100644 --- a/crates/db_schema/src/impls/email_verification.rs +++ b/crates/db_schema/src/impls/email_verification.rs @@ -7,7 +7,7 @@ use crate::{ verification_token, }, source::email_verification::{EmailVerification, EmailVerificationForm}, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{ dsl::{now, IntervalDsl}, @@ -19,16 +19,19 @@ use diesel::{ use diesel_async::RunQueryDsl; impl EmailVerification { - pub async fn create(pool: &DbPool, form: &EmailVerificationForm) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn create( + mut pool: &mut impl GetConn, + form: &EmailVerificationForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(email_verification) .values(form) .get_result::(conn) .await } - pub async fn read_for_token(pool: &DbPool, token: &str) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read_for_token(mut pool: &mut impl GetConn, token: &str) -> Result { + let conn = &mut *pool.get_conn().await?; email_verification .filter(verification_token.eq(token)) .filter(published.gt(now - 7.days())) @@ -36,10 +39,10 @@ impl EmailVerification { .await } pub async fn delete_old_tokens_for_local_user( - pool: &DbPool, + mut pool: &mut impl GetConn, local_user_id_: LocalUserId, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::delete(email_verification.filter(local_user_id.eq(local_user_id_))) .execute(conn) .await diff --git a/crates/db_schema/src/impls/federation_allowlist.rs b/crates/db_schema/src/impls/federation_allowlist.rs index c71ffd1cf..1b03e81c1 100644 --- a/crates/db_schema/src/impls/federation_allowlist.rs +++ b/crates/db_schema/src/impls/federation_allowlist.rs @@ -4,14 +4,17 @@ use crate::{ federation_allowlist::{FederationAllowList, FederationAllowListForm}, instance::Instance, }, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error}; use diesel_async::{AsyncPgConnection, RunQueryDsl}; impl FederationAllowList { - pub async fn replace(pool: &DbPool, list_opt: Option>) -> Result<(), Error> { - let conn = &mut get_conn(pool).await?; + pub async fn replace( + mut pool: &mut impl GetConn, + list_opt: Option>, + ) -> Result<(), Error> { + let conn = &mut *pool.get_conn().await?; conn .build_transaction() .run(|conn| { diff --git a/crates/db_schema/src/impls/federation_blocklist.rs b/crates/db_schema/src/impls/federation_blocklist.rs index 917bf57a3..bf596321a 100644 --- a/crates/db_schema/src/impls/federation_blocklist.rs +++ b/crates/db_schema/src/impls/federation_blocklist.rs @@ -4,14 +4,17 @@ use crate::{ federation_blocklist::{FederationBlockList, FederationBlockListForm}, instance::Instance, }, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error}; use diesel_async::{AsyncPgConnection, RunQueryDsl}; impl FederationBlockList { - pub async fn replace(pool: &DbPool, list_opt: Option>) -> Result<(), Error> { - let conn = &mut get_conn(pool).await?; + pub async fn replace( + mut pool: &mut impl GetConn, + list_opt: Option>, + ) -> Result<(), Error> { + let conn = &mut *pool.get_conn().await?; conn .build_transaction() .run(|conn| { diff --git a/crates/db_schema/src/impls/instance.rs b/crates/db_schema/src/impls/instance.rs index e5a8caba3..f999e6fee 100644 --- a/crates/db_schema/src/impls/instance.rs +++ b/crates/db_schema/src/impls/instance.rs @@ -2,7 +2,7 @@ use crate::{ newtypes::InstanceId, schema::{federation_allowlist, federation_blocklist, instance}, source::instance::{Instance, InstanceForm}, - utils::{get_conn, naive_now, DbPool}, + utils::{naive_now, DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::{AsyncPgConnection, RunQueryDsl}; @@ -42,23 +42,26 @@ impl Instance { /// Attempt to read Instance column for the given domain. If it doesnt exist, insert a new one. /// There is no need for update as the domain of an existing instance cant change. - pub async fn read_or_create(pool: &DbPool, domain: String) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read_or_create(mut pool: &mut impl GetConn, domain: String) -> Result { + let conn = &mut *pool.get_conn().await?; Self::read_or_create_with_conn(conn, domain).await } - pub async fn delete(pool: &DbPool, instance_id: InstanceId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn delete( + mut pool: &mut impl GetConn, + instance_id: InstanceId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete(instance::table.find(instance_id)) .execute(conn) .await } #[cfg(test)] - pub async fn delete_all(pool: &DbPool) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn delete_all(mut pool: &mut impl GetConn) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete(instance::table).execute(conn).await } - pub async fn allowlist(pool: &DbPool) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn allowlist(mut pool: &mut impl GetConn) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; instance::table .inner_join(federation_allowlist::table) .select(instance::all_columns) @@ -66,8 +69,8 @@ impl Instance { .await } - pub async fn blocklist(pool: &DbPool) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn blocklist(mut pool: &mut impl GetConn) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; instance::table .inner_join(federation_blocklist::table) .select(instance::all_columns) @@ -75,8 +78,8 @@ impl Instance { .await } - pub async fn linked(pool: &DbPool) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn linked(mut pool: &mut impl GetConn) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; instance::table .left_join(federation_blocklist::table) .filter(federation_blocklist::id.is_null()) diff --git a/crates/db_schema/src/impls/language.rs b/crates/db_schema/src/impls/language.rs index da9e0ca9d..0d2aa0785 100644 --- a/crates/db_schema/src/impls/language.rs +++ b/crates/db_schema/src/impls/language.rs @@ -3,14 +3,14 @@ use crate::{ newtypes::LanguageId, schema::language::dsl::{code, id, language}, source::language::Language, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{result::Error, QueryDsl}; use diesel_async::{AsyncPgConnection, RunQueryDsl}; impl Language { - pub async fn read_all(pool: &DbPool) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn read_all(mut pool: &mut impl GetConn) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; Self::read_all_conn(conn).await } @@ -18,18 +18,21 @@ impl Language { language.load::(conn).await } - pub async fn read_from_id(pool: &DbPool, id_: LanguageId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read_from_id( + mut pool: &mut impl GetConn, + id_: LanguageId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; language.filter(id.eq(id_)).first::(conn).await } /// Attempts to find the given language code and return its ID. If not found, returns none. pub async fn read_id_from_code( - pool: &DbPool, + mut pool: &mut impl GetConn, code_: Option<&str>, ) -> Result, Error> { if let Some(code_) = code_ { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; Ok( language .filter(code.eq(code_)) diff --git a/crates/db_schema/src/impls/local_site.rs b/crates/db_schema/src/impls/local_site.rs index b9e920d15..e5ca31448 100644 --- a/crates/db_schema/src/impls/local_site.rs +++ b/crates/db_schema/src/impls/local_site.rs @@ -1,32 +1,38 @@ use crate::{ schema::local_site::dsl::local_site, source::local_site::{LocalSite, LocalSiteInsertForm, LocalSiteUpdateForm}, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error}; use diesel_async::RunQueryDsl; impl LocalSite { - pub async fn create(pool: &DbPool, form: &LocalSiteInsertForm) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn create( + mut pool: &mut impl GetConn, + form: &LocalSiteInsertForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(local_site) .values(form) .get_result::(conn) .await } - pub async fn read(pool: &DbPool) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read(mut pool: &mut impl GetConn) -> Result { + let conn = &mut *pool.get_conn().await?; local_site.first::(conn).await } - pub async fn update(pool: &DbPool, form: &LocalSiteUpdateForm) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn update( + mut pool: &mut impl GetConn, + form: &LocalSiteUpdateForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::update(local_site) .set(form) .get_result::(conn) .await } - pub async fn delete(pool: &DbPool) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn delete(mut pool: &mut impl GetConn) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete(local_site).execute(conn).await } } diff --git a/crates/db_schema/src/impls/local_site_rate_limit.rs b/crates/db_schema/src/impls/local_site_rate_limit.rs index b1af5f869..48fe95338 100644 --- a/crates/db_schema/src/impls/local_site_rate_limit.rs +++ b/crates/db_schema/src/impls/local_site_rate_limit.rs @@ -5,30 +5,36 @@ use crate::{ LocalSiteRateLimitInsertForm, LocalSiteRateLimitUpdateForm, }, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error}; use diesel_async::RunQueryDsl; impl LocalSiteRateLimit { - pub async fn read(pool: &DbPool) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read(mut pool: &mut impl GetConn) -> Result { + let conn = &mut *pool.get_conn().await?; local_site_rate_limit::table.first::(conn).await } - pub async fn create(pool: &DbPool, form: &LocalSiteRateLimitInsertForm) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn create( + mut pool: &mut impl GetConn, + form: &LocalSiteRateLimitInsertForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(local_site_rate_limit::table) .values(form) .get_result::(conn) .await } - pub async fn update(pool: &DbPool, form: &LocalSiteRateLimitUpdateForm) -> Result<(), Error> { + pub async fn update( + mut pool: &mut impl GetConn, + form: &LocalSiteRateLimitUpdateForm, + ) -> Result<(), Error> { // avoid error "There are no changes to save. This query cannot be built" if form.is_empty() { return Ok(()); } - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(local_site_rate_limit::table) .set(form) .get_result::(conn) diff --git a/crates/db_schema/src/impls/local_user.rs b/crates/db_schema/src/impls/local_user.rs index c8ae23627..992121f27 100644 --- a/crates/db_schema/src/impls/local_user.rs +++ b/crates/db_schema/src/impls/local_user.rs @@ -13,7 +13,7 @@ use crate::{ local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm}, }, traits::Crud, - utils::{get_conn, naive_now, DbPool}, + utils::{naive_now, DbPool, GetConn}, }; use bcrypt::{hash, DEFAULT_COST}; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; @@ -21,11 +21,11 @@ use diesel_async::RunQueryDsl; impl LocalUser { pub async fn update_password( - pool: &DbPool, + mut pool: &mut impl GetConn, local_user_id: LocalUserId, new_password: &str, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let password_hash = hash(new_password, DEFAULT_COST).expect("Couldn't hash password"); diesel::update(local_user.find(local_user_id)) @@ -37,8 +37,10 @@ impl LocalUser { .await } - pub async fn set_all_users_email_verified(pool: &DbPool) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn set_all_users_email_verified( + mut pool: &mut impl GetConn, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; diesel::update(local_user) .set(email_verified.eq(true)) .get_results::(conn) @@ -46,18 +48,18 @@ impl LocalUser { } pub async fn set_all_users_registration_applications_accepted( - pool: &DbPool, + mut pool: &mut impl GetConn, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(local_user) .set(accepted_application.eq(true)) .get_results::(conn) .await } - pub async fn is_email_taken(pool: &DbPool, email_: &str) -> Result { + pub async fn is_email_taken(mut pool: &mut impl GetConn, email_: &str) -> Result { use diesel::dsl::{exists, select}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; select(exists(local_user.filter(email.eq(email_)))) .get_result(conn) .await @@ -69,18 +71,18 @@ impl Crud for LocalUser { type InsertForm = LocalUserInsertForm; type UpdateForm = LocalUserUpdateForm; type IdType = LocalUserId; - async fn read(pool: &DbPool, local_user_id: LocalUserId) -> Result { - let conn = &mut get_conn(pool).await?; + async fn read(mut pool: &mut impl GetConn, local_user_id: LocalUserId) -> Result { + let conn = &mut *pool.get_conn().await?; local_user.find(local_user_id).first::(conn).await } - async fn delete(pool: &DbPool, local_user_id: LocalUserId) -> Result { - let conn = &mut get_conn(pool).await?; + async fn delete(mut pool: &mut impl GetConn, local_user_id: LocalUserId) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete(local_user.find(local_user_id)) .execute(conn) .await } - async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { + let conn = &mut *pool.get_conn().await?; let mut form_with_encrypted_password = form.clone(); let password_hash = hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password"); @@ -104,11 +106,11 @@ impl Crud for LocalUser { Ok(local_user_) } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, local_user_id: LocalUserId, form: &Self::UpdateForm, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(local_user.find(local_user_id)) .set(form) .get_result::(conn) diff --git a/crates/db_schema/src/impls/moderator.rs b/crates/db_schema/src/impls/moderator.rs index ab8398cf3..11df68e6e 100644 --- a/crates/db_schema/src/impls/moderator.rs +++ b/crates/db_schema/src/impls/moderator.rs @@ -32,7 +32,7 @@ use crate::{ ModTransferCommunityForm, }, traits::Crud, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error, QueryDsl}; use diesel_async::RunQueryDsl; @@ -42,24 +42,28 @@ impl Crud for ModRemovePost { type InsertForm = ModRemovePostForm; type UpdateForm = ModRemovePostForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::mod_remove_post::dsl::mod_remove_post; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; mod_remove_post.find(from_id).first::(conn).await } - async fn create(pool: &DbPool, form: &ModRemovePostForm) -> Result { + async fn create(mut pool: &mut impl GetConn, form: &ModRemovePostForm) -> Result { use crate::schema::mod_remove_post::dsl::mod_remove_post; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(mod_remove_post) .values(form) .get_result::(conn) .await } - async fn update(pool: &DbPool, from_id: i32, form: &ModRemovePostForm) -> Result { + async fn update( + mut pool: &mut impl GetConn, + from_id: i32, + form: &ModRemovePostForm, + ) -> Result { use crate::schema::mod_remove_post::dsl::mod_remove_post; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(mod_remove_post.find(from_id)) .set(form) .get_result::(conn) @@ -72,24 +76,28 @@ impl Crud for ModLockPost { type InsertForm = ModLockPostForm; type UpdateForm = ModLockPostForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::mod_lock_post::dsl::mod_lock_post; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; mod_lock_post.find(from_id).first::(conn).await } - async fn create(pool: &DbPool, form: &ModLockPostForm) -> Result { + async fn create(mut pool: &mut impl GetConn, form: &ModLockPostForm) -> Result { use crate::schema::mod_lock_post::dsl::mod_lock_post; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(mod_lock_post) .values(form) .get_result::(conn) .await } - async fn update(pool: &DbPool, from_id: i32, form: &ModLockPostForm) -> Result { + async fn update( + mut pool: &mut impl GetConn, + from_id: i32, + form: &ModLockPostForm, + ) -> Result { use crate::schema::mod_lock_post::dsl::mod_lock_post; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(mod_lock_post.find(from_id)) .set(form) .get_result::(conn) @@ -102,24 +110,28 @@ impl Crud for ModFeaturePost { type InsertForm = ModFeaturePostForm; type UpdateForm = ModFeaturePostForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::mod_feature_post::dsl::mod_feature_post; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; mod_feature_post.find(from_id).first::(conn).await } - async fn create(pool: &DbPool, form: &ModFeaturePostForm) -> Result { + async fn create(mut pool: &mut impl GetConn, form: &ModFeaturePostForm) -> Result { use crate::schema::mod_feature_post::dsl::mod_feature_post; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(mod_feature_post) .values(form) .get_result::(conn) .await } - async fn update(pool: &DbPool, from_id: i32, form: &ModFeaturePostForm) -> Result { + async fn update( + mut pool: &mut impl GetConn, + from_id: i32, + form: &ModFeaturePostForm, + ) -> Result { use crate::schema::mod_feature_post::dsl::mod_feature_post; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(mod_feature_post.find(from_id)) .set(form) .get_result::(conn) @@ -132,24 +144,28 @@ impl Crud for ModRemoveComment { type InsertForm = ModRemoveCommentForm; type UpdateForm = ModRemoveCommentForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::mod_remove_comment::dsl::mod_remove_comment; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; mod_remove_comment.find(from_id).first::(conn).await } - async fn create(pool: &DbPool, form: &ModRemoveCommentForm) -> Result { + async fn create(mut pool: &mut impl GetConn, form: &ModRemoveCommentForm) -> Result { use crate::schema::mod_remove_comment::dsl::mod_remove_comment; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(mod_remove_comment) .values(form) .get_result::(conn) .await } - async fn update(pool: &DbPool, from_id: i32, form: &ModRemoveCommentForm) -> Result { + async fn update( + mut pool: &mut impl GetConn, + from_id: i32, + form: &ModRemoveCommentForm, + ) -> Result { use crate::schema::mod_remove_comment::dsl::mod_remove_comment; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(mod_remove_comment.find(from_id)) .set(form) .get_result::(conn) @@ -162,15 +178,18 @@ impl Crud for ModRemoveCommunity { type InsertForm = ModRemoveCommunityForm; type UpdateForm = ModRemoveCommunityForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::mod_remove_community::dsl::mod_remove_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; mod_remove_community.find(from_id).first::(conn).await } - async fn create(pool: &DbPool, form: &ModRemoveCommunityForm) -> Result { + async fn create( + mut pool: &mut impl GetConn, + form: &ModRemoveCommunityForm, + ) -> Result { use crate::schema::mod_remove_community::dsl::mod_remove_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(mod_remove_community) .values(form) .get_result::(conn) @@ -178,12 +197,12 @@ impl Crud for ModRemoveCommunity { } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, from_id: i32, form: &ModRemoveCommunityForm, ) -> Result { use crate::schema::mod_remove_community::dsl::mod_remove_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(mod_remove_community.find(from_id)) .set(form) .get_result::(conn) @@ -196,18 +215,21 @@ impl Crud for ModBanFromCommunity { type InsertForm = ModBanFromCommunityForm; type UpdateForm = ModBanFromCommunityForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; mod_ban_from_community .find(from_id) .first::(conn) .await } - async fn create(pool: &DbPool, form: &ModBanFromCommunityForm) -> Result { + async fn create( + mut pool: &mut impl GetConn, + form: &ModBanFromCommunityForm, + ) -> Result { use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(mod_ban_from_community) .values(form) .get_result::(conn) @@ -215,12 +237,12 @@ impl Crud for ModBanFromCommunity { } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, from_id: i32, form: &ModBanFromCommunityForm, ) -> Result { use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(mod_ban_from_community.find(from_id)) .set(form) .get_result::(conn) @@ -233,24 +255,28 @@ impl Crud for ModBan { type InsertForm = ModBanForm; type UpdateForm = ModBanForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::mod_ban::dsl::mod_ban; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; mod_ban.find(from_id).first::(conn).await } - async fn create(pool: &DbPool, form: &ModBanForm) -> Result { + async fn create(mut pool: &mut impl GetConn, form: &ModBanForm) -> Result { use crate::schema::mod_ban::dsl::mod_ban; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(mod_ban) .values(form) .get_result::(conn) .await } - async fn update(pool: &DbPool, from_id: i32, form: &ModBanForm) -> Result { + async fn update( + mut pool: &mut impl GetConn, + from_id: i32, + form: &ModBanForm, + ) -> Result { use crate::schema::mod_ban::dsl::mod_ban; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(mod_ban.find(from_id)) .set(form) .get_result::(conn) @@ -264,24 +290,28 @@ impl Crud for ModHideCommunity { type UpdateForm = ModHideCommunityForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::mod_hide_community::dsl::mod_hide_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; mod_hide_community.find(from_id).first::(conn).await } - async fn create(pool: &DbPool, form: &ModHideCommunityForm) -> Result { + async fn create(mut pool: &mut impl GetConn, form: &ModHideCommunityForm) -> Result { use crate::schema::mod_hide_community::dsl::mod_hide_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(mod_hide_community) .values(form) .get_result::(conn) .await } - async fn update(pool: &DbPool, from_id: i32, form: &ModHideCommunityForm) -> Result { + async fn update( + mut pool: &mut impl GetConn, + from_id: i32, + form: &ModHideCommunityForm, + ) -> Result { use crate::schema::mod_hide_community::dsl::mod_hide_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(mod_hide_community.find(from_id)) .set(form) .get_result::(conn) @@ -294,24 +324,28 @@ impl Crud for ModAddCommunity { type InsertForm = ModAddCommunityForm; type UpdateForm = ModAddCommunityForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::mod_add_community::dsl::mod_add_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; mod_add_community.find(from_id).first::(conn).await } - async fn create(pool: &DbPool, form: &ModAddCommunityForm) -> Result { + async fn create(mut pool: &mut impl GetConn, form: &ModAddCommunityForm) -> Result { use crate::schema::mod_add_community::dsl::mod_add_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(mod_add_community) .values(form) .get_result::(conn) .await } - async fn update(pool: &DbPool, from_id: i32, form: &ModAddCommunityForm) -> Result { + async fn update( + mut pool: &mut impl GetConn, + from_id: i32, + form: &ModAddCommunityForm, + ) -> Result { use crate::schema::mod_add_community::dsl::mod_add_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(mod_add_community.find(from_id)) .set(form) .get_result::(conn) @@ -324,18 +358,21 @@ impl Crud for ModTransferCommunity { type InsertForm = ModTransferCommunityForm; type UpdateForm = ModTransferCommunityForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::mod_transfer_community::dsl::mod_transfer_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; mod_transfer_community .find(from_id) .first::(conn) .await } - async fn create(pool: &DbPool, form: &ModTransferCommunityForm) -> Result { + async fn create( + mut pool: &mut impl GetConn, + form: &ModTransferCommunityForm, + ) -> Result { use crate::schema::mod_transfer_community::dsl::mod_transfer_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(mod_transfer_community) .values(form) .get_result::(conn) @@ -343,12 +380,12 @@ impl Crud for ModTransferCommunity { } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, from_id: i32, form: &ModTransferCommunityForm, ) -> Result { use crate::schema::mod_transfer_community::dsl::mod_transfer_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(mod_transfer_community.find(from_id)) .set(form) .get_result::(conn) @@ -361,24 +398,28 @@ impl Crud for ModAdd { type InsertForm = ModAddForm; type UpdateForm = ModAddForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::mod_add::dsl::mod_add; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; mod_add.find(from_id).first::(conn).await } - async fn create(pool: &DbPool, form: &ModAddForm) -> Result { + async fn create(mut pool: &mut impl GetConn, form: &ModAddForm) -> Result { use crate::schema::mod_add::dsl::mod_add; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(mod_add) .values(form) .get_result::(conn) .await } - async fn update(pool: &DbPool, from_id: i32, form: &ModAddForm) -> Result { + async fn update( + mut pool: &mut impl GetConn, + from_id: i32, + form: &ModAddForm, + ) -> Result { use crate::schema::mod_add::dsl::mod_add; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(mod_add.find(from_id)) .set(form) .get_result::(conn) @@ -391,24 +432,28 @@ impl Crud for AdminPurgePerson { type InsertForm = AdminPurgePersonForm; type UpdateForm = AdminPurgePersonForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::admin_purge_person::dsl::admin_purge_person; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; admin_purge_person.find(from_id).first::(conn).await } - async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { + async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { use crate::schema::admin_purge_person::dsl::admin_purge_person; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(admin_purge_person) .values(form) .get_result::(conn) .await } - async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result { + async fn update( + mut pool: &mut impl GetConn, + from_id: i32, + form: &Self::InsertForm, + ) -> Result { use crate::schema::admin_purge_person::dsl::admin_purge_person; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(admin_purge_person.find(from_id)) .set(form) .get_result::(conn) @@ -421,27 +466,31 @@ impl Crud for AdminPurgeCommunity { type InsertForm = AdminPurgeCommunityForm; type UpdateForm = AdminPurgeCommunityForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::admin_purge_community::dsl::admin_purge_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; admin_purge_community .find(from_id) .first::(conn) .await } - async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { + async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { use crate::schema::admin_purge_community::dsl::admin_purge_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(admin_purge_community) .values(form) .get_result::(conn) .await } - async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result { + async fn update( + mut pool: &mut impl GetConn, + from_id: i32, + form: &Self::InsertForm, + ) -> Result { use crate::schema::admin_purge_community::dsl::admin_purge_community; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(admin_purge_community.find(from_id)) .set(form) .get_result::(conn) @@ -454,24 +503,28 @@ impl Crud for AdminPurgePost { type InsertForm = AdminPurgePostForm; type UpdateForm = AdminPurgePostForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::admin_purge_post::dsl::admin_purge_post; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; admin_purge_post.find(from_id).first::(conn).await } - async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { + async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { use crate::schema::admin_purge_post::dsl::admin_purge_post; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(admin_purge_post) .values(form) .get_result::(conn) .await } - async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result { + async fn update( + mut pool: &mut impl GetConn, + from_id: i32, + form: &Self::InsertForm, + ) -> Result { use crate::schema::admin_purge_post::dsl::admin_purge_post; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(admin_purge_post.find(from_id)) .set(form) .get_result::(conn) @@ -484,24 +537,28 @@ impl Crud for AdminPurgeComment { type InsertForm = AdminPurgeCommentForm; type UpdateForm = AdminPurgeCommentForm; type IdType = i32; - async fn read(pool: &DbPool, from_id: i32) -> Result { + async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { use crate::schema::admin_purge_comment::dsl::admin_purge_comment; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; admin_purge_comment.find(from_id).first::(conn).await } - async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { + async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { use crate::schema::admin_purge_comment::dsl::admin_purge_comment; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(admin_purge_comment) .values(form) .get_result::(conn) .await } - async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result { + async fn update( + mut pool: &mut impl GetConn, + from_id: i32, + form: &Self::InsertForm, + ) -> Result { use crate::schema::admin_purge_comment::dsl::admin_purge_comment; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(admin_purge_comment.find(from_id)) .set(form) .get_result::(conn) diff --git a/crates/db_schema/src/impls/password_reset_request.rs b/crates/db_schema/src/impls/password_reset_request.rs index 85ad4cf01..b58312500 100644 --- a/crates/db_schema/src/impls/password_reset_request.rs +++ b/crates/db_schema/src/impls/password_reset_request.rs @@ -8,7 +8,7 @@ use crate::{ }, source::password_reset_request::{PasswordResetRequest, PasswordResetRequestForm}, traits::Crud, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{ dsl::{insert_into, now, IntervalDsl}, @@ -24,26 +24,32 @@ impl Crud for PasswordResetRequest { type InsertForm = PasswordResetRequestForm; type UpdateForm = PasswordResetRequestForm; type IdType = i32; - async fn read(pool: &DbPool, password_reset_request_id: i32) -> Result { - let conn = &mut get_conn(pool).await?; + async fn read( + mut pool: &mut impl GetConn, + password_reset_request_id: i32, + ) -> Result { + let conn = &mut *pool.get_conn().await?; password_reset_request .find(password_reset_request_id) .first::(conn) .await } - async fn create(pool: &DbPool, form: &PasswordResetRequestForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn create( + mut pool: &mut impl GetConn, + form: &PasswordResetRequestForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(password_reset_request) .values(form) .get_result::(conn) .await } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, password_reset_request_id: i32, form: &PasswordResetRequestForm, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(password_reset_request.find(password_reset_request_id)) .set(form) .get_result::(conn) @@ -53,7 +59,7 @@ impl Crud for PasswordResetRequest { impl PasswordResetRequest { pub async fn create_token( - pool: &DbPool, + mut pool: &mut impl GetConn, from_local_user_id: LocalUserId, token: &str, ) -> Result { @@ -68,8 +74,11 @@ impl PasswordResetRequest { Self::create(pool, &form).await } - pub async fn read_from_token(pool: &DbPool, token: &str) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read_from_token( + mut pool: &mut impl GetConn, + token: &str, + ) -> Result { + let conn = &mut *pool.get_conn().await?; let mut hasher = Sha256::new(); hasher.update(token); let token_hash: String = bytes_to_hex(hasher.finalize().to_vec()); @@ -81,10 +90,10 @@ impl PasswordResetRequest { } pub async fn get_recent_password_resets_count( - pool: &DbPool, + mut pool: &mut impl GetConn, user_id: LocalUserId, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; password_reset_request .filter(local_user_id.eq(user_id)) .filter(published.gt(now - 1.days())) diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index 5c23f8071..7fdef962f 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -9,7 +9,7 @@ use crate::{ PersonUpdateForm, }, traits::{ApubActor, Crud, Followable}, - utils::{functions::lower, get_conn, naive_now, DbPool}, + utils::{functions::lower, naive_now, DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, JoinOnDsl, QueryDsl}; use diesel_async::RunQueryDsl; @@ -19,33 +19,33 @@ impl Crud for Person { type InsertForm = PersonInsertForm; type UpdateForm = PersonUpdateForm; type IdType = PersonId; - async fn read(pool: &DbPool, person_id: PersonId) -> Result { - let conn = &mut get_conn(pool).await?; + async fn read(mut pool: &mut impl GetConn, person_id: PersonId) -> Result { + let conn = &mut *pool.get_conn().await?; person::table .filter(person::deleted.eq(false)) .find(person_id) .first::(conn) .await } - async fn delete(pool: &DbPool, person_id: PersonId) -> Result { - let conn = &mut get_conn(pool).await?; + async fn delete(mut pool: &mut impl GetConn, person_id: PersonId) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete(person::table.find(person_id)) .execute(conn) .await } - async fn create(pool: &DbPool, form: &PersonInsertForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn create(mut pool: &mut impl GetConn, form: &PersonInsertForm) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(person::table) .values(form) .get_result::(conn) .await } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, person_id: PersonId, form: &PersonUpdateForm, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(person::table.find(person_id)) .set(form) .get_result::(conn) @@ -57,8 +57,8 @@ impl Person { /// Update or insert the person. /// /// This is necessary for federation, because Activitypub doesnt distinguish between these actions. - pub async fn upsert(pool: &DbPool, form: &PersonInsertForm) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn upsert(mut pool: &mut impl GetConn, form: &PersonInsertForm) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(person::table) .values(form) .on_conflict(person::actor_id) @@ -67,8 +67,11 @@ impl Person { .get_result::(conn) .await } - pub async fn delete_account(pool: &DbPool, person_id: PersonId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn delete_account( + mut pool: &mut impl GetConn, + person_id: PersonId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; // Set the local user info to none diesel::update(local_user::table.filter(local_user::person_id.eq(person_id))) @@ -104,8 +107,11 @@ pub fn is_banned(banned_: bool, expires: Option) -> bool #[async_trait] impl ApubActor for Person { - async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + async fn read_from_apub_id( + mut pool: &mut impl GetConn, + object_id: &DbUrl, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; Ok( person::table .filter(person::deleted.eq(false)) @@ -118,11 +124,11 @@ impl ApubActor for Person { } async fn read_from_name( - pool: &DbPool, + mut pool: &mut impl GetConn, from_name: &str, include_deleted: bool, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let mut q = person::table .into_boxed() .filter(person::local.eq(true)) @@ -134,11 +140,11 @@ impl ApubActor for Person { } async fn read_from_name_and_domain( - pool: &DbPool, + mut pool: &mut impl GetConn, person_name: &str, for_domain: &str, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; person::table .inner_join(instance::table) @@ -153,9 +159,9 @@ impl ApubActor for Person { #[async_trait] impl Followable for PersonFollower { type Form = PersonFollowerForm; - async fn follow(pool: &DbPool, form: &PersonFollowerForm) -> Result { + async fn follow(mut pool: &mut impl GetConn, form: &PersonFollowerForm) -> Result { use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(person_follower) .values(form) .on_conflict((follower_id, person_id)) @@ -164,12 +170,19 @@ impl Followable for PersonFollower { .get_result::(conn) .await } - async fn follow_accepted(_: &DbPool, _: CommunityId, _: PersonId) -> Result { + async fn follow_accepted( + _: &mut impl GetConn, + _: CommunityId, + _: PersonId, + ) -> Result { unimplemented!() } - async fn unfollow(pool: &DbPool, form: &PersonFollowerForm) -> Result { + async fn unfollow( + mut pool: &mut impl GetConn, + form: &PersonFollowerForm, + ) -> Result { use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::delete( person_follower .filter(follower_id.eq(&form.follower_id)) @@ -182,10 +195,10 @@ impl Followable for PersonFollower { impl PersonFollower { pub async fn list_followers( - pool: &DbPool, + mut pool: &mut impl GetConn, for_person_id: PersonId, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; person_follower::table .inner_join(person::table.on(person_follower::follower_id.eq(person::id))) .filter(person_follower::person_id.eq(for_person_id)) diff --git a/crates/db_schema/src/impls/person_block.rs b/crates/db_schema/src/impls/person_block.rs index 9cd275563..538ee16a5 100644 --- a/crates/db_schema/src/impls/person_block.rs +++ b/crates/db_schema/src/impls/person_block.rs @@ -3,18 +3,18 @@ use crate::{ schema::person_block::dsl::{person_block, person_id, target_id}, source::person_block::{PersonBlock, PersonBlockForm}, traits::Blockable, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; impl PersonBlock { pub async fn read( - pool: &DbPool, + mut pool: &mut impl GetConn, for_person_id: PersonId, for_recipient_id: PersonId, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; person_block .filter(person_id.eq(for_person_id)) .filter(target_id.eq(for_recipient_id)) @@ -26,8 +26,11 @@ impl PersonBlock { #[async_trait] impl Blockable for PersonBlock { type Form = PersonBlockForm; - async fn block(pool: &DbPool, person_block_form: &PersonBlockForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn block( + mut pool: &mut impl GetConn, + person_block_form: &PersonBlockForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(person_block) .values(person_block_form) .on_conflict((person_id, target_id)) @@ -36,8 +39,11 @@ impl Blockable for PersonBlock { .get_result::(conn) .await } - async fn unblock(pool: &DbPool, person_block_form: &Self::Form) -> Result { - let conn = &mut get_conn(pool).await?; + async fn unblock( + mut pool: &mut impl GetConn, + person_block_form: &Self::Form, + ) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete( person_block .filter(person_id.eq(person_block_form.person_id)) diff --git a/crates/db_schema/src/impls/person_mention.rs b/crates/db_schema/src/impls/person_mention.rs index 559340e78..6f023f14b 100644 --- a/crates/db_schema/src/impls/person_mention.rs +++ b/crates/db_schema/src/impls/person_mention.rs @@ -3,7 +3,7 @@ use crate::{ schema::person_mention::dsl::{comment_id, person_mention, read, recipient_id}, source::person_mention::{PersonMention, PersonMentionInsertForm, PersonMentionUpdateForm}, traits::Crud, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; @@ -13,16 +13,22 @@ impl Crud for PersonMention { type InsertForm = PersonMentionInsertForm; type UpdateForm = PersonMentionUpdateForm; type IdType = PersonMentionId; - async fn read(pool: &DbPool, person_mention_id: PersonMentionId) -> Result { - let conn = &mut get_conn(pool).await?; + async fn read( + mut pool: &mut impl GetConn, + person_mention_id: PersonMentionId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; person_mention .find(person_mention_id) .first::(conn) .await } - async fn create(pool: &DbPool, person_mention_form: &Self::InsertForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn create( + mut pool: &mut impl GetConn, + person_mention_form: &Self::InsertForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; // since the return here isnt utilized, we dont need to do an update // but get_result doesnt return the existing row here insert_into(person_mention) @@ -35,11 +41,11 @@ impl Crud for PersonMention { } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, person_mention_id: PersonMentionId, person_mention_form: &Self::UpdateForm, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(person_mention.find(person_mention_id)) .set(person_mention_form) .get_result::(conn) @@ -49,10 +55,10 @@ impl Crud for PersonMention { impl PersonMention { pub async fn mark_all_as_read( - pool: &DbPool, + mut pool: &mut impl GetConn, for_recipient_id: PersonId, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update( person_mention .filter(recipient_id.eq(for_recipient_id)) @@ -64,11 +70,11 @@ impl PersonMention { } pub async fn read_by_comment_and_person( - pool: &DbPool, + mut pool: &mut impl GetConn, for_comment_id: CommentId, for_recipient_id: PersonId, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; person_mention .filter(comment_id.eq(for_comment_id)) .filter(recipient_id.eq(for_recipient_id)) diff --git a/crates/db_schema/src/impls/post.rs b/crates/db_schema/src/impls/post.rs index 6a4d53d3a..15982390f 100644 --- a/crates/db_schema/src/impls/post.rs +++ b/crates/db_schema/src/impls/post.rs @@ -27,7 +27,7 @@ use crate::{ PostUpdateForm, }, traits::{Crud, Likeable, Readable, Saveable}, - utils::{get_conn, naive_now, DbPool, DELETED_REPLACEMENT_TEXT, FETCH_LIMIT_MAX}, + utils::{naive_now, DbPool, GetConn, DELETED_REPLACEMENT_TEXT, FETCH_LIMIT_MAX}, }; use ::url::Url; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods}; @@ -38,18 +38,18 @@ impl Crud for Post { type InsertForm = PostInsertForm; type UpdateForm = PostUpdateForm; type IdType = PostId; - async fn read(pool: &DbPool, post_id: PostId) -> Result { - let conn = &mut get_conn(pool).await?; + async fn read(mut pool: &mut impl GetConn, post_id: PostId) -> Result { + let conn = &mut *pool.get_conn().await?; post.find(post_id).first::(conn).await } - async fn delete(pool: &DbPool, post_id: PostId) -> Result { - let conn = &mut get_conn(pool).await?; + async fn delete(mut pool: &mut impl GetConn, post_id: PostId) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete(post.find(post_id)).execute(conn).await } - async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(post) .values(form) .on_conflict(ap_id) @@ -60,11 +60,11 @@ impl Crud for Post { } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, post_id: PostId, new_post: &Self::UpdateForm, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(post.find(post_id)) .set(new_post) .get_result::(conn) @@ -74,10 +74,10 @@ impl Crud for Post { impl Post { pub async fn list_for_community( - pool: &DbPool, + mut pool: &mut impl GetConn, the_community_id: CommunityId, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; post .filter(community_id.eq(the_community_id)) .filter(deleted.eq(false)) @@ -90,10 +90,10 @@ impl Post { } pub async fn list_featured_for_community( - pool: &DbPool, + mut pool: &mut impl GetConn, the_community_id: CommunityId, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; post .filter(community_id.eq(the_community_id)) .filter(deleted.eq(false)) @@ -106,10 +106,10 @@ impl Post { } pub async fn permadelete_for_creator( - pool: &DbPool, + mut pool: &mut impl GetConn, for_creator_id: PersonId, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(post.filter(creator_id.eq(for_creator_id))) .set(( @@ -124,12 +124,12 @@ impl Post { } pub async fn update_removed_for_creator( - pool: &DbPool, + mut pool: &mut impl GetConn, for_creator_id: PersonId, for_community_id: Option, new_removed: bool, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let mut update = diesel::update(post).into_boxed(); update = update.filter(creator_id.eq(for_creator_id)); @@ -148,8 +148,11 @@ impl Post { person_id == post_creator_id } - pub async fn read_from_apub_id(pool: &DbPool, object_id: Url) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn read_from_apub_id( + mut pool: &mut impl GetConn, + object_id: Url, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let object_id: DbUrl = object_id.into(); Ok( post @@ -162,10 +165,10 @@ impl Post { } pub async fn fetch_pictrs_posts_for_creator( - pool: &DbPool, + mut pool: &mut impl GetConn, for_creator_id: PersonId, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let pictrs_search = "%pictrs/image%"; post @@ -177,10 +180,10 @@ impl Post { /// Sets the url and thumbnails fields to None pub async fn remove_pictrs_post_images_and_thumbnails_for_creator( - pool: &DbPool, + mut pool: &mut impl GetConn, for_creator_id: PersonId, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let pictrs_search = "%pictrs/image%"; diesel::update( @@ -197,10 +200,10 @@ impl Post { } pub async fn fetch_pictrs_posts_for_community( - pool: &DbPool, + mut pool: &mut impl GetConn, for_community_id: CommunityId, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let pictrs_search = "%pictrs/image%"; post .filter(community_id.eq(for_community_id)) @@ -211,10 +214,10 @@ impl Post { /// Sets the url and thumbnails fields to None pub async fn remove_pictrs_post_images_and_thumbnails_for_community( - pool: &DbPool, + mut pool: &mut impl GetConn, for_community_id: CommunityId, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let pictrs_search = "%pictrs/image%"; diesel::update( @@ -235,9 +238,9 @@ impl Post { impl Likeable for PostLike { type Form = PostLikeForm; type IdType = PostId; - async fn like(pool: &DbPool, post_like_form: &PostLikeForm) -> Result { + async fn like(mut pool: &mut impl GetConn, post_like_form: &PostLikeForm) -> Result { use crate::schema::post_like::dsl::{person_id, post_id, post_like}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(post_like) .values(post_like_form) .on_conflict((post_id, person_id)) @@ -246,9 +249,13 @@ impl Likeable for PostLike { .get_result::(conn) .await } - async fn remove(pool: &DbPool, person_id: PersonId, post_id: PostId) -> Result { + async fn remove( + mut pool: &mut impl GetConn, + person_id: PersonId, + post_id: PostId, + ) -> Result { use crate::schema::post_like::dsl; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::delete( dsl::post_like .filter(dsl::post_id.eq(post_id)) @@ -262,9 +269,12 @@ impl Likeable for PostLike { #[async_trait] impl Saveable for PostSaved { type Form = PostSavedForm; - async fn save(pool: &DbPool, post_saved_form: &PostSavedForm) -> Result { + async fn save( + mut pool: &mut impl GetConn, + post_saved_form: &PostSavedForm, + ) -> Result { use crate::schema::post_saved::dsl::{person_id, post_id, post_saved}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(post_saved) .values(post_saved_form) .on_conflict((post_id, person_id)) @@ -273,9 +283,12 @@ impl Saveable for PostSaved { .get_result::(conn) .await } - async fn unsave(pool: &DbPool, post_saved_form: &PostSavedForm) -> Result { + async fn unsave( + mut pool: &mut impl GetConn, + post_saved_form: &PostSavedForm, + ) -> Result { use crate::schema::post_saved::dsl::{person_id, post_id, post_saved}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::delete( post_saved .filter(post_id.eq(post_saved_form.post_id)) @@ -289,9 +302,12 @@ impl Saveable for PostSaved { #[async_trait] impl Readable for PostRead { type Form = PostReadForm; - async fn mark_as_read(pool: &DbPool, post_read_form: &PostReadForm) -> Result { + async fn mark_as_read( + mut pool: &mut impl GetConn, + post_read_form: &PostReadForm, + ) -> Result { use crate::schema::post_read::dsl::{person_id, post_id, post_read}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; insert_into(post_read) .values(post_read_form) .on_conflict((post_id, person_id)) @@ -301,9 +317,12 @@ impl Readable for PostRead { .await } - async fn mark_as_unread(pool: &DbPool, post_read_form: &PostReadForm) -> Result { + async fn mark_as_unread( + mut pool: &mut impl GetConn, + post_read_form: &PostReadForm, + ) -> Result { use crate::schema::post_read::dsl::{person_id, post_id, post_read}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::delete( post_read .filter(post_id.eq(post_read_form.post_id)) diff --git a/crates/db_schema/src/impls/post_report.rs b/crates/db_schema/src/impls/post_report.rs index ece7d0901..d089490f3 100644 --- a/crates/db_schema/src/impls/post_report.rs +++ b/crates/db_schema/src/impls/post_report.rs @@ -3,7 +3,7 @@ use crate::{ schema::post_report::dsl::{post_report, resolved, resolver_id, updated}, source::post_report::{PostReport, PostReportForm}, traits::Reportable, - utils::{get_conn, naive_now, DbPool}, + utils::{naive_now, DbPool, GetConn}, }; use diesel::{ dsl::{insert_into, update}, @@ -18,8 +18,11 @@ impl Reportable for PostReport { type Form = PostReportForm; type IdType = PostReportId; - async fn report(pool: &DbPool, post_report_form: &PostReportForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn report( + mut pool: &mut impl GetConn, + post_report_form: &PostReportForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(post_report) .values(post_report_form) .get_result::(conn) @@ -27,11 +30,11 @@ impl Reportable for PostReport { } async fn resolve( - pool: &DbPool, + mut pool: &mut impl GetConn, report_id: Self::IdType, by_resolver_id: PersonId, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; update(post_report.find(report_id)) .set(( resolved.eq(true), @@ -43,11 +46,11 @@ impl Reportable for PostReport { } async fn unresolve( - pool: &DbPool, + mut pool: &mut impl GetConn, report_id: Self::IdType, by_resolver_id: PersonId, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; update(post_report.find(report_id)) .set(( resolved.eq(false), diff --git a/crates/db_schema/src/impls/private_message.rs b/crates/db_schema/src/impls/private_message.rs index cf6782270..23d67c36b 100644 --- a/crates/db_schema/src/impls/private_message.rs +++ b/crates/db_schema/src/impls/private_message.rs @@ -3,7 +3,7 @@ use crate::{ schema::private_message::dsl::{ap_id, private_message, read, recipient_id}, source::private_message::{PrivateMessage, PrivateMessageInsertForm, PrivateMessageUpdateForm}, traits::Crud, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; @@ -15,16 +15,19 @@ impl Crud for PrivateMessage { type InsertForm = PrivateMessageInsertForm; type UpdateForm = PrivateMessageUpdateForm; type IdType = PrivateMessageId; - async fn read(pool: &DbPool, private_message_id: PrivateMessageId) -> Result { - let conn = &mut get_conn(pool).await?; + async fn read( + mut pool: &mut impl GetConn, + private_message_id: PrivateMessageId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; private_message .find(private_message_id) .first::(conn) .await } - async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(private_message) .values(form) .on_conflict(ap_id) @@ -35,18 +38,18 @@ impl Crud for PrivateMessage { } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, private_message_id: PrivateMessageId, form: &Self::UpdateForm, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(private_message.find(private_message_id)) .set(form) .get_result::(conn) .await } - async fn delete(pool: &DbPool, pm_id: Self::IdType) -> Result { - let conn = &mut get_conn(pool).await?; + async fn delete(mut pool: &mut impl GetConn, pm_id: Self::IdType) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete(private_message.find(pm_id)) .execute(conn) .await @@ -55,10 +58,10 @@ impl Crud for PrivateMessage { impl PrivateMessage { pub async fn mark_all_as_read( - pool: &DbPool, + mut pool: &mut impl GetConn, for_recipient_id: PersonId, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update( private_message .filter(recipient_id.eq(for_recipient_id)) @@ -70,10 +73,10 @@ impl PrivateMessage { } pub async fn read_from_apub_id( - pool: &DbPool, + mut pool: &mut impl GetConn, object_id: Url, ) -> Result, LemmyError> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let object_id: DbUrl = object_id.into(); Ok( private_message diff --git a/crates/db_schema/src/impls/private_message_report.rs b/crates/db_schema/src/impls/private_message_report.rs index 5f2498c28..e7ed32109 100644 --- a/crates/db_schema/src/impls/private_message_report.rs +++ b/crates/db_schema/src/impls/private_message_report.rs @@ -3,7 +3,7 @@ use crate::{ schema::private_message_report::dsl::{private_message_report, resolved, resolver_id, updated}, source::private_message_report::{PrivateMessageReport, PrivateMessageReportForm}, traits::Reportable, - utils::{get_conn, naive_now, DbPool}, + utils::{naive_now, DbPool, GetConn}, }; use diesel::{ dsl::{insert_into, update}, @@ -18,8 +18,11 @@ impl Reportable for PrivateMessageReport { type Form = PrivateMessageReportForm; type IdType = PrivateMessageReportId; - async fn report(pool: &DbPool, pm_report_form: &PrivateMessageReportForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn report( + mut pool: &mut impl GetConn, + pm_report_form: &PrivateMessageReportForm, + ) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(private_message_report) .values(pm_report_form) .get_result::(conn) @@ -27,11 +30,11 @@ impl Reportable for PrivateMessageReport { } async fn resolve( - pool: &DbPool, + mut pool: &mut impl GetConn, report_id: Self::IdType, by_resolver_id: PersonId, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; update(private_message_report.find(report_id)) .set(( resolved.eq(true), @@ -43,11 +46,11 @@ impl Reportable for PrivateMessageReport { } async fn unresolve( - pool: &DbPool, + mut pool: &mut impl GetConn, report_id: Self::IdType, by_resolver_id: PersonId, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; update(private_message_report.find(report_id)) .set(( resolved.eq(false), diff --git a/crates/db_schema/src/impls/registration_application.rs b/crates/db_schema/src/impls/registration_application.rs index 208b01d01..aa50b4ef1 100644 --- a/crates/db_schema/src/impls/registration_application.rs +++ b/crates/db_schema/src/impls/registration_application.rs @@ -7,7 +7,7 @@ use crate::{ RegistrationApplicationUpdateForm, }, traits::Crud, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; @@ -18,33 +18,33 @@ impl Crud for RegistrationApplication { type UpdateForm = RegistrationApplicationUpdateForm; type IdType = i32; - async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { + let conn = &mut *pool.get_conn().await?; insert_into(registration_application) .values(form) .get_result::(conn) .await } - async fn read(pool: &DbPool, id_: Self::IdType) -> Result { - let conn = &mut get_conn(pool).await?; + async fn read(mut pool: &mut impl GetConn, id_: Self::IdType) -> Result { + let conn = &mut *pool.get_conn().await?; registration_application.find(id_).first::(conn).await } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, id_: Self::IdType, form: &Self::UpdateForm, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(registration_application.find(id_)) .set(form) .get_result::(conn) .await } - async fn delete(pool: &DbPool, id_: Self::IdType) -> Result { - let conn = &mut get_conn(pool).await?; + async fn delete(mut pool: &mut impl GetConn, id_: Self::IdType) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete(registration_application.find(id_)) .execute(conn) .await @@ -53,10 +53,10 @@ impl Crud for RegistrationApplication { impl RegistrationApplication { pub async fn find_by_local_user_id( - pool: &DbPool, + mut pool: &mut impl GetConn, local_user_id_: LocalUserId, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; registration_application .filter(local_user_id.eq(local_user_id_)) .first::(conn) diff --git a/crates/db_schema/src/impls/secret.rs b/crates/db_schema/src/impls/secret.rs index 4e0d9c1bd..75d62b92d 100644 --- a/crates/db_schema/src/impls/secret.rs +++ b/crates/db_schema/src/impls/secret.rs @@ -1,7 +1,7 @@ use crate::{ schema::secret::dsl::secret, source::secret::Secret, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::result::Error; use diesel_async::RunQueryDsl; @@ -9,12 +9,12 @@ use diesel_async::RunQueryDsl; impl Secret { /// Initialize the Secrets from the DB. /// Warning: You should only call this once. - pub async fn init(pool: &DbPool) -> Result { + pub async fn init(mut pool: &mut impl GetConn) -> Result { Self::read_secrets(pool).await } - async fn read_secrets(pool: &DbPool) -> Result { - let conn = &mut get_conn(pool).await?; + async fn read_secrets(mut pool: &mut impl GetConn) -> Result { + let conn = &mut *pool.get_conn().await?; secret.first::(conn).await } } diff --git a/crates/db_schema/src/impls/site.rs b/crates/db_schema/src/impls/site.rs index 3363edc93..101a2e872 100644 --- a/crates/db_schema/src/impls/site.rs +++ b/crates/db_schema/src/impls/site.rs @@ -6,7 +6,7 @@ use crate::{ site::{Site, SiteInsertForm, SiteUpdateForm}, }, traits::Crud, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; @@ -19,12 +19,12 @@ impl Crud for Site { type IdType = SiteId; /// Use SiteView::read_local, or Site::read_from_apub_id instead - async fn read(_pool: &DbPool, _site_id: SiteId) -> Result { + async fn read(_pool: &mut impl GetConn, _site_id: SiteId) -> Result { unimplemented!() } - async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { - let conn = &mut get_conn(pool).await?; + async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { + let conn = &mut *pool.get_conn().await?; let is_new_site = match &form.actor_id { Some(id_) => Site::read_from_apub_id(pool, id_).await?.is_none(), None => true, @@ -48,26 +48,29 @@ impl Crud for Site { } async fn update( - pool: &DbPool, + mut pool: &mut impl GetConn, site_id: SiteId, new_site: &Self::UpdateForm, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; diesel::update(site.find(site_id)) .set(new_site) .get_result::(conn) .await } - async fn delete(pool: &DbPool, site_id: SiteId) -> Result { - let conn = &mut get_conn(pool).await?; + async fn delete(mut pool: &mut impl GetConn, site_id: SiteId) -> Result { + let conn = &mut *pool.get_conn().await?; diesel::delete(site.find(site_id)).execute(conn).await } } impl Site { - pub async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn read_from_apub_id( + mut pool: &mut impl GetConn, + object_id: &DbUrl, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; Ok( site .filter(actor_id.eq(object_id)) @@ -79,8 +82,8 @@ impl Site { } // TODO this needs fixed - pub async fn read_remote_sites(pool: &DbPool) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn read_remote_sites(mut pool: &mut impl GetConn) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; site.order_by(id).offset(1).get_results::(conn).await } diff --git a/crates/db_schema/src/impls/tagline.rs b/crates/db_schema/src/impls/tagline.rs index ec985a3c8..e74c54a16 100644 --- a/crates/db_schema/src/impls/tagline.rs +++ b/crates/db_schema/src/impls/tagline.rs @@ -2,18 +2,18 @@ use crate::{ newtypes::LocalSiteId, schema::tagline::dsl::{local_site_id, tagline}, source::tagline::{Tagline, TaglineForm}, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::{AsyncPgConnection, RunQueryDsl}; impl Tagline { pub async fn replace( - pool: &DbPool, + mut pool: &mut impl GetConn, for_local_site_id: LocalSiteId, list_content: Option>, ) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; if let Some(list) = list_content { conn .build_transaction() @@ -54,8 +54,11 @@ impl Tagline { .get_results::(conn) .await } - pub async fn get_all(pool: &DbPool, for_local_site_id: LocalSiteId) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn get_all( + mut pool: &mut impl GetConn, + for_local_site_id: LocalSiteId, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; Self::get_all_conn(conn, for_local_site_id).await } } diff --git a/crates/db_schema/src/traits.rs b/crates/db_schema/src/traits.rs index 12b92b3d9..60d5e1209 100644 --- a/crates/db_schema/src/traits.rs +++ b/crates/db_schema/src/traits.rs @@ -1,6 +1,6 @@ use crate::{ newtypes::{CommunityId, DbUrl, PersonId}, - utils::DbPool, + utils::{DbPool, GetConn}, }; use diesel::result::Error; @@ -9,17 +9,21 @@ pub trait Crud { type InsertForm; type UpdateForm; type IdType; - async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result + async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result where Self: Sized; - async fn read(pool: &DbPool, id: Self::IdType) -> Result + async fn read(mut pool: &mut impl GetConn, id: Self::IdType) -> Result where Self: Sized; /// 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. - async fn update(pool: &DbPool, id: Self::IdType, form: &Self::UpdateForm) -> Result + async fn update( + mut pool: &mut impl GetConn, + id: Self::IdType, + form: &Self::UpdateForm, + ) -> Result where Self: Sized; - async fn delete(_pool: &DbPool, _id: Self::IdType) -> Result + async fn delete(_pool: &mut impl GetConn, _id: Self::IdType) -> Result where Self: Sized, Self::IdType: Send, @@ -31,17 +35,17 @@ pub trait Crud { #[async_trait] pub trait Followable { type Form; - async fn follow(pool: &DbPool, form: &Self::Form) -> Result + async fn follow(mut pool: &mut impl GetConn, form: &Self::Form) -> Result where Self: Sized; async fn follow_accepted( - pool: &DbPool, + mut pool: &mut impl GetConn, community_id: CommunityId, person_id: PersonId, ) -> Result where Self: Sized; - async fn unfollow(pool: &DbPool, form: &Self::Form) -> Result + async fn unfollow(mut pool: &mut impl GetConn, form: &Self::Form) -> Result where Self: Sized; } @@ -49,10 +53,10 @@ pub trait Followable { #[async_trait] pub trait Joinable { type Form; - async fn join(pool: &DbPool, form: &Self::Form) -> Result + async fn join(mut pool: &mut impl GetConn, form: &Self::Form) -> Result where Self: Sized; - async fn leave(pool: &DbPool, form: &Self::Form) -> Result + async fn leave(mut pool: &mut impl GetConn, form: &Self::Form) -> Result where Self: Sized; } @@ -61,11 +65,11 @@ pub trait Joinable { pub trait Likeable { type Form; type IdType; - async fn like(pool: &DbPool, form: &Self::Form) -> Result + async fn like(mut pool: &mut impl GetConn, form: &Self::Form) -> Result where Self: Sized; async fn remove( - pool: &DbPool, + mut pool: &mut impl GetConn, person_id: PersonId, item_id: Self::IdType, ) -> Result @@ -76,10 +80,10 @@ pub trait Likeable { #[async_trait] pub trait Bannable { type Form; - async fn ban(pool: &DbPool, form: &Self::Form) -> Result + async fn ban(mut pool: &mut impl GetConn, form: &Self::Form) -> Result where Self: Sized; - async fn unban(pool: &DbPool, form: &Self::Form) -> Result + async fn unban(mut pool: &mut impl GetConn, form: &Self::Form) -> Result where Self: Sized; } @@ -87,10 +91,10 @@ pub trait Bannable { #[async_trait] pub trait Saveable { type Form; - async fn save(pool: &DbPool, form: &Self::Form) -> Result + async fn save(mut pool: &mut impl GetConn, form: &Self::Form) -> Result where Self: Sized; - async fn unsave(pool: &DbPool, form: &Self::Form) -> Result + async fn unsave(mut pool: &mut impl GetConn, form: &Self::Form) -> Result where Self: Sized; } @@ -98,10 +102,10 @@ pub trait Saveable { #[async_trait] pub trait Blockable { type Form; - async fn block(pool: &DbPool, form: &Self::Form) -> Result + async fn block(mut pool: &mut impl GetConn, form: &Self::Form) -> Result where Self: Sized; - async fn unblock(pool: &DbPool, form: &Self::Form) -> Result + async fn unblock(mut pool: &mut impl GetConn, form: &Self::Form) -> Result where Self: Sized; } @@ -109,10 +113,10 @@ pub trait Blockable { #[async_trait] pub trait Readable { type Form; - async fn mark_as_read(pool: &DbPool, form: &Self::Form) -> Result + async fn mark_as_read(mut pool: &mut impl GetConn, form: &Self::Form) -> Result where Self: Sized; - async fn mark_as_unread(pool: &DbPool, form: &Self::Form) -> Result + async fn mark_as_unread(mut pool: &mut impl GetConn, form: &Self::Form) -> Result where Self: Sized; } @@ -121,18 +125,18 @@ pub trait Readable { pub trait Reportable { type Form; type IdType; - async fn report(pool: &DbPool, form: &Self::Form) -> Result + async fn report(mut pool: &mut impl GetConn, form: &Self::Form) -> Result where Self: Sized; async fn resolve( - pool: &DbPool, + mut pool: &mut impl GetConn, report_id: Self::IdType, resolver_id: PersonId, ) -> Result where Self: Sized; async fn unresolve( - pool: &DbPool, + mut pool: &mut impl GetConn, report_id: Self::IdType, resolver_id: PersonId, ) -> Result @@ -149,20 +153,23 @@ pub trait JoinView { #[async_trait] pub trait ApubActor { - async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result, Error> + async fn read_from_apub_id( + mut pool: &mut impl GetConn, + object_id: &DbUrl, + ) -> Result, Error> where Self: Sized; /// - 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 async fn read_from_name( - pool: &DbPool, + mut pool: &mut impl GetConn, actor_name: &str, include_deleted: bool, ) -> Result where Self: Sized; async fn read_from_name_and_domain( - pool: &DbPool, + mut pool: &mut impl GetConn, actor_name: &str, protocol_domain: &str, ) -> Result diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index e4f5d6cae..3db39d738 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -50,33 +50,48 @@ const POOL_TIMEOUT: Option = Some(Duration::from_secs(5)); pub type DbPool = Pool; #[async_trait] -pub trait GetConn { - type Conn: std::ops::Deref; +pub trait GetConn: Send { + type Conn<'conn>: std::ops::DerefMut + Send + where + Self: 'conn; - async fn get_conn(self) -> Result; + // Without `&mut`, `self` would move when this method is called, + // which prevents calling it multiple times on the same `impl GetConn`. + async fn get_conn<'conn>(&mut self) -> Result, DieselError> + where + 'life0: 'conn; //where + //Self::Conn: 'life0; } #[async_trait] impl<'a> GetConn for &'a DbPool { - type Conn = PooledConnection; + type Conn<'conn> = PooledConnection; - async fn get_conn(self) -> Result { + async fn get_conn<'conn>(&mut self) -> Result, DieselError> + where + 'life0: 'conn, //where + //Self::Conn: 'life0, + { self.get().await.map_err(|e| QueryBuilderError(e.into())) } } #[async_trait] -impl<'a> GetConn for &'a mut AsyncPgConnection { - type Conn = Self; +impl GetConn for AsyncPgConnection { + type Conn<'conn> = &'conn mut AsyncPgConnection; - async fn get_conn(self) -> Result { + async fn get_conn<'conn>(&mut self) -> Result, DieselError> + where + 'life0: 'conn, //where + //Self::Conn: 'life0, + { Ok(self) } } -pub async fn get_conn(getter: T) -> Result { +/*pub async fn get_conn(getter: T) -> Result { getter.get_conn().await -} +}*/ pub fn get_database_url_from_env() -> Result { env::var("LEMMY_DATABASE_URL") diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 4a5397b32..d2a1ea45c 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -31,7 +31,7 @@ use lemmy_db_schema::{ post::Post, }, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; use typed_builder::TypedBuilder; @@ -40,11 +40,11 @@ impl CommentReportView { /// /// * `report_id` - the report id to obtain pub async fn read( - pool: &DbPool, + mut pool: &mut impl GetConn, report_id: CommentReportId, my_person_id: PersonId, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2); @@ -96,14 +96,14 @@ impl CommentReportView { /// Returns the current unresolved post report count for the communities you mod pub async fn get_report_count( - pool: &DbPool, + mut pool: &mut impl GetConn, my_person_id: PersonId, admin: bool, community_id: Option, ) -> Result { use diesel::dsl::count; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let mut query = comment_report::table .inner_join(comment::table) diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index f3b1f83a8..a64771769 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -36,7 +36,7 @@ use lemmy_db_schema::{ post::Post, }, traits::JoinView, - utils::{fuzzy_search, get_conn, limit_and_offset, DbPool}, + utils::{fuzzy_search, limit_and_offset, DbPool, GetConn}, CommentSortType, ListingType, }; @@ -57,11 +57,11 @@ type CommentViewTuple = ( impl CommentView { pub async fn read( - pool: &DbPool, + mut pool: &mut impl GetConn, comment_id: CommentId, my_person_id: Option, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; // The left join below will return None in this case let person_id_join = my_person_id.unwrap_or(PersonId(-1)); @@ -431,7 +431,7 @@ mod tests { inserted_community: Community, } - async fn init_data(pool: &DbPool) -> Data { + async fn init_data(mut pool: &mut impl GetConn) -> Data { let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()) .await .unwrap(); @@ -781,7 +781,7 @@ mod tests { cleanup(data, pool).await; } - async fn cleanup(data: Data, pool: &DbPool) { + async fn cleanup(data: Data, mut pool: &mut impl GetConn) { CommentLike::remove(pool, data.inserted_person.id, data.inserted_comment_0.id) .await .unwrap(); @@ -804,7 +804,7 @@ mod tests { .unwrap(); } - async fn expected_comment_view(data: &Data, pool: &DbPool) -> CommentView { + async fn expected_comment_view(data: &Data, mut pool: &mut impl GetConn) -> CommentView { let agg = CommentAggregates::read(pool, data.inserted_comment_0.id) .await .unwrap(); diff --git a/crates/db_views/src/custom_emoji_view.rs b/crates/db_views/src/custom_emoji_view.rs index 66d583e32..bcde2d718 100644 --- a/crates/db_views/src/custom_emoji_view.rs +++ b/crates/db_views/src/custom_emoji_view.rs @@ -5,15 +5,15 @@ use lemmy_db_schema::{ newtypes::{CustomEmojiId, LocalSiteId}, schema::{custom_emoji, custom_emoji_keyword}, source::{custom_emoji::CustomEmoji, custom_emoji_keyword::CustomEmojiKeyword}, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; use std::collections::HashMap; type CustomEmojiTuple = (CustomEmoji, Option); impl CustomEmojiView { - pub async fn get(pool: &DbPool, emoji_id: CustomEmojiId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn get(mut pool: &mut impl GetConn, emoji_id: CustomEmojiId) -> Result { + let conn = &mut *pool.get_conn().await?; let emojis = custom_emoji::table .find(emoji_id) .left_join( @@ -35,8 +35,11 @@ impl CustomEmojiView { } } - pub async fn get_all(pool: &DbPool, for_local_site_id: LocalSiteId) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn get_all( + mut pool: &mut impl GetConn, + for_local_site_id: LocalSiteId, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let emojis = custom_emoji::table .filter(custom_emoji::local_site_id.eq(for_local_site_id)) .left_join( diff --git a/crates/db_views/src/local_user_view.rs b/crates/db_views/src/local_user_view.rs index f37986cc9..591dea7d2 100644 --- a/crates/db_views/src/local_user_view.rs +++ b/crates/db_views/src/local_user_view.rs @@ -7,14 +7,17 @@ use lemmy_db_schema::{ schema::{local_user, person, person_aggregates}, source::{local_user::LocalUser, person::Person}, traits::JoinView, - utils::{functions::lower, get_conn, DbPool}, + utils::{functions::lower, DbPool, GetConn}, }; type LocalUserViewTuple = (LocalUser, Person, PersonAggregates); impl LocalUserView { - pub async fn read(pool: &DbPool, local_user_id: LocalUserId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read( + mut pool: &mut impl GetConn, + local_user_id: LocalUserId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; let (local_user, person, counts) = local_user::table .find(local_user_id) @@ -34,8 +37,11 @@ impl LocalUserView { }) } - pub async fn read_person(pool: &DbPool, person_id: PersonId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read_person( + mut pool: &mut impl GetConn, + person_id: PersonId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; let (local_user, person, counts) = local_user::table .filter(person::id.eq(person_id)) .inner_join(person::table) @@ -54,8 +60,8 @@ impl LocalUserView { }) } - pub async fn read_from_name(pool: &DbPool, name: &str) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read_from_name(mut pool: &mut impl GetConn, name: &str) -> Result { + let conn = &mut *pool.get_conn().await?; let (local_user, person, counts) = local_user::table .filter(lower(person::name).eq(name.to_lowercase())) .inner_join(person::table) @@ -74,8 +80,11 @@ impl LocalUserView { }) } - pub async fn find_by_email_or_name(pool: &DbPool, name_or_email: &str) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn find_by_email_or_name( + mut pool: &mut impl GetConn, + name_or_email: &str, + ) -> Result { + let conn = &mut *pool.get_conn().await?; let (local_user, person, counts) = local_user::table .inner_join(person::table) .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id))) @@ -98,8 +107,8 @@ impl LocalUserView { }) } - pub async fn find_by_email(pool: &DbPool, from_email: &str) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn find_by_email(mut pool: &mut impl GetConn, from_email: &str) -> Result { + let conn = &mut *pool.get_conn().await?; let (local_user, person, counts) = local_user::table .inner_join(person::table) .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id))) @@ -118,8 +127,8 @@ impl LocalUserView { }) } - pub async fn list_admins_with_emails(pool: &DbPool) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list_admins_with_emails(mut pool: &mut impl GetConn) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let res = local_user::table .filter(person::admin.eq(true)) .filter(local_user::email.is_not_null()) diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index 19822c795..5627b4ba1 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -28,7 +28,7 @@ use lemmy_db_schema::{ post_report::PostReport, }, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; use typed_builder::TypedBuilder; @@ -49,11 +49,11 @@ impl PostReportView { /// /// * `report_id` - the report id to obtain pub async fn read( - pool: &DbPool, + mut pool: &mut impl GetConn, report_id: PostReportId, my_person_id: PersonId, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2); let ( @@ -121,13 +121,13 @@ impl PostReportView { /// returns the current unresolved post report count for the communities you mod pub async fn get_report_count( - pool: &DbPool, + mut pool: &mut impl GetConn, my_person_id: PersonId, admin: bool, community_id: Option, ) -> Result { use diesel::dsl::count; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let mut query = post_report::table .inner_join(post::table) .filter(post_report::resolved.eq(false)) diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index d1e974d8a..2a42b9e2f 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -40,7 +40,7 @@ use lemmy_db_schema::{ post::{Post, PostRead, PostSaved}, }, traits::JoinView, - utils::{fuzzy_search, get_conn, limit_and_offset, DbPool}, + utils::{fuzzy_search, limit_and_offset, DbPool, GetConn}, ListingType, SortType, }; @@ -65,12 +65,12 @@ sql_function!(fn coalesce(x: sql_types::Nullable, y: sql_type impl PostView { pub async fn read( - pool: &DbPool, + mut pool: &mut impl GetConn, post_id: PostId, my_person_id: Option, is_mod_or_admin: Option, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; // The left join below will return None in this case let person_id_join = my_person_id.unwrap_or(PersonId(-1)); @@ -510,7 +510,7 @@ mod tests { inserted_post: Post, } - async fn init_data(pool: &DbPool) -> Data { + async fn init_data(mut pool: &mut impl GetConn) -> Data { let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()) .await .unwrap(); @@ -930,7 +930,7 @@ mod tests { cleanup(data, pool).await; } - async fn cleanup(data: Data, pool: &DbPool) { + async fn cleanup(data: Data, mut pool: &mut impl GetConn) { let num_deleted = Post::delete(pool, data.inserted_post.id).await.unwrap(); Community::delete(pool, data.inserted_community.id) .await @@ -946,7 +946,7 @@ mod tests { assert_eq!(1, num_deleted); } - async fn expected_post_view(data: &Data, pool: &DbPool) -> PostView { + async fn expected_post_view(data: &Data, mut pool: &mut impl GetConn) -> PostView { let (inserted_person, inserted_community, inserted_post) = ( &data.inserted_person, &data.inserted_community, diff --git a/crates/db_views/src/private_message_report_view.rs b/crates/db_views/src/private_message_report_view.rs index 2bcad6f83..af404517b 100644 --- a/crates/db_views/src/private_message_report_view.rs +++ b/crates/db_views/src/private_message_report_view.rs @@ -10,7 +10,7 @@ use lemmy_db_schema::{ private_message_report::PrivateMessageReport, }, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; use typed_builder::TypedBuilder; @@ -26,8 +26,11 @@ impl PrivateMessageReportView { /// returns the PrivateMessageReportView for the provided report_id /// /// * `report_id` - the report id to obtain - pub async fn read(pool: &DbPool, report_id: PrivateMessageReportId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read( + mut pool: &mut impl GetConn, + report_id: PrivateMessageReportId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2); let (private_message_report, private_message, private_message_creator, creator, resolver) = @@ -64,9 +67,9 @@ impl PrivateMessageReportView { } /// Returns the current unresolved post report count for the communities you mod - pub async fn get_report_count(pool: &DbPool) -> Result { + pub async fn get_report_count(mut pool: &mut impl GetConn) -> Result { use diesel::dsl::count; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; private_message_report::table .inner_join(private_message::table) diff --git a/crates/db_views/src/private_message_view.rs b/crates/db_views/src/private_message_view.rs index 76b817a96..a044629fb 100644 --- a/crates/db_views/src/private_message_view.rs +++ b/crates/db_views/src/private_message_view.rs @@ -14,7 +14,7 @@ use lemmy_db_schema::{ schema::{person, private_message}, source::{person::Person, private_message::PrivateMessage}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; use tracing::debug; use typed_builder::TypedBuilder; @@ -22,8 +22,11 @@ use typed_builder::TypedBuilder; type PrivateMessageViewTuple = (PrivateMessage, Person, Person); impl PrivateMessageView { - pub async fn read(pool: &DbPool, private_message_id: PrivateMessageId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read( + mut pool: &mut impl GetConn, + private_message_id: PrivateMessageId, + ) -> Result { + let conn = &mut *pool.get_conn().await?; let person_alias_1 = diesel::alias!(person as person1); let (private_message, creator, recipient) = private_message::table @@ -49,9 +52,12 @@ impl PrivateMessageView { } /// Gets the number of unread messages - pub async fn get_unread_messages(pool: &DbPool, my_person_id: PersonId) -> Result { + pub async fn get_unread_messages( + mut pool: &mut impl GetConn, + my_person_id: PersonId, + ) -> Result { use diesel::dsl::count; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; private_message::table .filter(private_message::read.eq(false)) .filter(private_message::recipient_id.eq(my_person_id)) diff --git a/crates/db_views/src/registration_application_view.rs b/crates/db_views/src/registration_application_view.rs index 9963ed466..de7b4fa08 100644 --- a/crates/db_views/src/registration_application_view.rs +++ b/crates/db_views/src/registration_application_view.rs @@ -16,7 +16,7 @@ use lemmy_db_schema::{ registration_application::RegistrationApplication, }, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; use typed_builder::TypedBuilder; @@ -24,8 +24,11 @@ type RegistrationApplicationViewTuple = (RegistrationApplication, LocalUser, Person, Option); impl RegistrationApplicationView { - pub async fn read(pool: &DbPool, registration_application_id: i32) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read( + mut pool: &mut impl GetConn, + registration_application_id: i32, + ) -> Result { + let conn = &mut *pool.get_conn().await?; let person_alias_1 = diesel::alias!(person as person1); let (registration_application, creator_local_user, creator, admin) = @@ -58,8 +61,11 @@ impl RegistrationApplicationView { } /// Returns the current unread registration_application count - pub async fn get_unread_count(pool: &DbPool, verified_email_only: bool) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn get_unread_count( + mut pool: &mut impl GetConn, + verified_email_only: bool, + ) -> Result { + let conn = &mut *pool.get_conn().await?; let person_alias_1 = diesel::alias!(person as person1); let mut query = registration_application::table diff --git a/crates/db_views/src/site_view.rs b/crates/db_views/src/site_view.rs index a1d0231a2..e8e06e4fe 100644 --- a/crates/db_views/src/site_view.rs +++ b/crates/db_views/src/site_view.rs @@ -5,12 +5,12 @@ use lemmy_db_schema::{ aggregates::structs::SiteAggregates, schema::{local_site, local_site_rate_limit, site, site_aggregates}, source::{local_site::LocalSite, local_site_rate_limit::LocalSiteRateLimit, site::Site}, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; impl SiteView { - pub async fn read_local(pool: &DbPool) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read_local(mut pool: &mut impl GetConn) -> Result { + let conn = &mut *pool.get_conn().await?; let (mut site, local_site, local_site_rate_limit, counts) = site::table .inner_join(local_site::table) .inner_join( diff --git a/crates/db_views_actor/src/comment_reply_view.rs b/crates/db_views_actor/src/comment_reply_view.rs index 42c3a53e0..a0589cc7c 100644 --- a/crates/db_views_actor/src/comment_reply_view.rs +++ b/crates/db_views_actor/src/comment_reply_view.rs @@ -33,7 +33,7 @@ use lemmy_db_schema::{ post::Post, }, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, CommentSortType, }; use typed_builder::TypedBuilder; @@ -55,11 +55,11 @@ type CommentReplyViewTuple = ( impl CommentReplyView { pub async fn read( - pool: &DbPool, + mut pool: &mut impl GetConn, comment_reply_id: CommentReplyId, my_person_id: Option, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let person_alias_1 = diesel::alias!(person as person1); // The left join below will return None in this case @@ -155,10 +155,13 @@ impl CommentReplyView { } /// Gets the number of unread replies - pub async fn get_unread_replies(pool: &DbPool, my_person_id: PersonId) -> Result { + pub async fn get_unread_replies( + mut pool: &mut impl GetConn, + my_person_id: PersonId, + ) -> Result { use diesel::dsl::count; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; comment_reply::table .inner_join(comment::table) diff --git a/crates/db_views_actor/src/community_block_view.rs b/crates/db_views_actor/src/community_block_view.rs index d87bea37f..836426c67 100644 --- a/crates/db_views_actor/src/community_block_view.rs +++ b/crates/db_views_actor/src/community_block_view.rs @@ -6,14 +6,17 @@ use lemmy_db_schema::{ schema::{community, community_block, person}, source::{community::Community, person::Person}, traits::JoinView, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; type CommunityBlockViewTuple = (Person, Community); impl CommunityBlockView { - pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn for_person( + mut pool: &mut impl GetConn, + person_id: PersonId, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let res = community_block::table .inner_join(person::table) .inner_join(community::table) diff --git a/crates/db_views_actor/src/community_follower_view.rs b/crates/db_views_actor/src/community_follower_view.rs index ccc7ae706..b056b174b 100644 --- a/crates/db_views_actor/src/community_follower_view.rs +++ b/crates/db_views_actor/src/community_follower_view.rs @@ -6,14 +6,17 @@ use lemmy_db_schema::{ schema::{community, community_follower, person}, source::{community::Community, person::Person}, traits::JoinView, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; type CommunityFollowerViewTuple = (Community, Person); impl CommunityFollowerView { - pub async fn for_community(pool: &DbPool, community_id: CommunityId) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn for_community( + mut pool: &mut impl GetConn, + community_id: CommunityId, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let res = community_follower::table .inner_join(community::table) .inner_join(person::table) @@ -26,8 +29,11 @@ impl CommunityFollowerView { Ok(res.into_iter().map(Self::from_tuple).collect()) } - pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn for_person( + mut pool: &mut impl GetConn, + person_id: PersonId, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let res = community_follower::table .inner_join(community::table) .inner_join(person::table) diff --git a/crates/db_views_actor/src/community_moderator_view.rs b/crates/db_views_actor/src/community_moderator_view.rs index afdfbfb28..3007ca885 100644 --- a/crates/db_views_actor/src/community_moderator_view.rs +++ b/crates/db_views_actor/src/community_moderator_view.rs @@ -6,14 +6,17 @@ use lemmy_db_schema::{ schema::{community, community_moderator, person}, source::{community::Community, person::Person}, traits::JoinView, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; type CommunityModeratorViewTuple = (Community, Person); impl CommunityModeratorView { - pub async fn for_community(pool: &DbPool, community_id: CommunityId) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn for_community( + mut pool: &mut impl GetConn, + community_id: CommunityId, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let res = community_moderator::table .inner_join(community::table) .inner_join(person::table) @@ -25,8 +28,11 @@ impl CommunityModeratorView { Ok(res.into_iter().map(Self::from_tuple).collect()) } - pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn for_person( + mut pool: &mut impl GetConn, + person_id: PersonId, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let res = community_moderator::table .inner_join(community::table) .inner_join(person::table) @@ -42,8 +48,8 @@ impl CommunityModeratorView { /// Finds all communities first mods / creators /// Ideally this should be a group by, but diesel doesn't support it yet - pub async fn get_community_first_mods(pool: &DbPool) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn get_community_first_mods(mut pool: &mut impl GetConn) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let res = community_moderator::table .inner_join(community::table) .inner_join(person::table) diff --git a/crates/db_views_actor/src/community_person_ban_view.rs b/crates/db_views_actor/src/community_person_ban_view.rs index 35eacf0f7..89ccce104 100644 --- a/crates/db_views_actor/src/community_person_ban_view.rs +++ b/crates/db_views_actor/src/community_person_ban_view.rs @@ -5,16 +5,16 @@ use lemmy_db_schema::{ newtypes::{CommunityId, PersonId}, schema::{community, community_person_ban, person}, source::{community::Community, person::Person}, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; impl CommunityPersonBanView { pub async fn get( - pool: &DbPool, + mut pool: &mut impl GetConn, from_person_id: PersonId, from_community_id: CommunityId, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let (community, person) = community_person_ban::table .inner_join(community::table) .inner_join(person::table) diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index 94bcdaf92..403f6b9b8 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -19,7 +19,7 @@ use lemmy_db_schema::{ local_user::LocalUser, }, traits::JoinView, - utils::{fuzzy_search, get_conn, limit_and_offset, DbPool}, + utils::{fuzzy_search, limit_and_offset, DbPool, GetConn}, ListingType, SortType, }; @@ -34,12 +34,12 @@ type CommunityViewTuple = ( impl CommunityView { pub async fn read( - pool: &DbPool, + mut pool: &mut impl GetConn, community_id: CommunityId, my_person_id: Option, is_mod_or_admin: Option, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; // The left join below will return None in this case let person_id_join = my_person_id.unwrap_or(PersonId(-1)); @@ -86,7 +86,7 @@ impl CommunityView { } pub async fn is_mod_or_admin( - pool: &DbPool, + mut pool: &mut impl GetConn, person_id: PersonId, community_id: CommunityId, ) -> Result { diff --git a/crates/db_views_actor/src/person_block_view.rs b/crates/db_views_actor/src/person_block_view.rs index 6e10ee7b6..1443c6538 100644 --- a/crates/db_views_actor/src/person_block_view.rs +++ b/crates/db_views_actor/src/person_block_view.rs @@ -6,14 +6,17 @@ use lemmy_db_schema::{ schema::{person, person_block}, source::person::Person, traits::JoinView, - utils::{get_conn, DbPool}, + utils::{DbPool, GetConn}, }; type PersonBlockViewTuple = (Person, Person); impl PersonBlockView { - pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn for_person( + mut pool: &mut impl GetConn, + person_id: PersonId, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let target_person_alias = diesel::alias!(person as person1); let res = person_block::table diff --git a/crates/db_views_actor/src/person_mention_view.rs b/crates/db_views_actor/src/person_mention_view.rs index 803abdb39..183ad3886 100644 --- a/crates/db_views_actor/src/person_mention_view.rs +++ b/crates/db_views_actor/src/person_mention_view.rs @@ -34,7 +34,7 @@ use lemmy_db_schema::{ post::Post, }, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, CommentSortType, }; use typed_builder::TypedBuilder; @@ -56,11 +56,11 @@ type PersonMentionViewTuple = ( impl PersonMentionView { pub async fn read( - pool: &DbPool, + mut pool: &mut impl GetConn, person_mention_id: PersonMentionId, my_person_id: Option, ) -> Result { - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; let person_alias_1 = diesel::alias!(person as person1); // The left join below will return None in this case @@ -156,9 +156,12 @@ impl PersonMentionView { } /// Gets the number of unread mentions - pub async fn get_unread_mentions(pool: &DbPool, my_person_id: PersonId) -> Result { + pub async fn get_unread_mentions( + mut pool: &mut impl GetConn, + my_person_id: PersonId, + ) -> Result { use diesel::dsl::count; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; person_mention::table .inner_join(comment::table) diff --git a/crates/db_views_actor/src/person_view.rs b/crates/db_views_actor/src/person_view.rs index 2a7a2ce79..1918334b7 100644 --- a/crates/db_views_actor/src/person_view.rs +++ b/crates/db_views_actor/src/person_view.rs @@ -14,7 +14,7 @@ use lemmy_db_schema::{ schema::{person, person_aggregates}, source::person::Person, traits::JoinView, - utils::{fuzzy_search, get_conn, limit_and_offset, DbPool}, + utils::{fuzzy_search, limit_and_offset, DbPool, GetConn}, SortType, }; use std::iter::Iterator; @@ -23,8 +23,8 @@ use typed_builder::TypedBuilder; type PersonViewTuple = (Person, PersonAggregates); impl PersonView { - pub async fn read(pool: &DbPool, person_id: PersonId) -> Result { - let conn = &mut get_conn(pool).await?; + pub async fn read(mut pool: &mut impl GetConn, person_id: PersonId) -> Result { + let conn = &mut *pool.get_conn().await?; let res = person::table .find(person_id) .inner_join(person_aggregates::table) @@ -34,8 +34,8 @@ impl PersonView { Ok(Self::from_tuple(res)) } - pub async fn admins(pool: &DbPool) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn admins(mut pool: &mut impl GetConn) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let admins = person::table .inner_join(person_aggregates::table) .select((person::all_columns, person_aggregates::all_columns)) @@ -48,8 +48,8 @@ impl PersonView { Ok(admins.into_iter().map(Self::from_tuple).collect()) } - pub async fn banned(pool: &DbPool) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn banned(mut pool: &mut impl GetConn) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let banned = person::table .inner_join(person_aggregates::table) .select((person::all_columns, person_aggregates::all_columns)) diff --git a/crates/db_views_moderator/src/admin_purge_comment_view.rs b/crates/db_views_moderator/src/admin_purge_comment_view.rs index 12e47fbbc..09fbc292c 100644 --- a/crates/db_views_moderator/src/admin_purge_comment_view.rs +++ b/crates/db_views_moderator/src/admin_purge_comment_view.rs @@ -14,14 +14,17 @@ use lemmy_db_schema::{ schema::{admin_purge_comment, person, post}, source::{moderator::AdminPurgeComment, person::Person, post::Post}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type AdminPurgeCommentViewTuple = (AdminPurgeComment, Option, Post); impl AdminPurgeCommentView { - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; let show_mod_names_expr = show_mod_names.as_sql::(); diff --git a/crates/db_views_moderator/src/admin_purge_community_view.rs b/crates/db_views_moderator/src/admin_purge_community_view.rs index e3a7a7897..86cec46d1 100644 --- a/crates/db_views_moderator/src/admin_purge_community_view.rs +++ b/crates/db_views_moderator/src/admin_purge_community_view.rs @@ -14,14 +14,17 @@ use lemmy_db_schema::{ schema::{admin_purge_community, person}, source::{moderator::AdminPurgeCommunity, person::Person}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, Option); impl AdminPurgeCommunityView { - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; let show_mod_names_expr = show_mod_names.as_sql::(); diff --git a/crates/db_views_moderator/src/admin_purge_person_view.rs b/crates/db_views_moderator/src/admin_purge_person_view.rs index fff5b2d51..5a18a5cde 100644 --- a/crates/db_views_moderator/src/admin_purge_person_view.rs +++ b/crates/db_views_moderator/src/admin_purge_person_view.rs @@ -14,14 +14,17 @@ use lemmy_db_schema::{ schema::{admin_purge_person, person}, source::{moderator::AdminPurgePerson, person::Person}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type AdminPurgePersonViewTuple = (AdminPurgePerson, Option); impl AdminPurgePersonView { - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; diff --git a/crates/db_views_moderator/src/admin_purge_post_view.rs b/crates/db_views_moderator/src/admin_purge_post_view.rs index e37e66b1b..53ca2a4ef 100644 --- a/crates/db_views_moderator/src/admin_purge_post_view.rs +++ b/crates/db_views_moderator/src/admin_purge_post_view.rs @@ -14,14 +14,17 @@ use lemmy_db_schema::{ schema::{admin_purge_post, community, person}, source::{community::Community, moderator::AdminPurgePost, person::Person}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type AdminPurgePostViewTuple = (AdminPurgePost, Option, Community); impl AdminPurgePostView { - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; diff --git a/crates/db_views_moderator/src/mod_add_community_view.rs b/crates/db_views_moderator/src/mod_add_community_view.rs index 6df6376f5..c36ccd996 100644 --- a/crates/db_views_moderator/src/mod_add_community_view.rs +++ b/crates/db_views_moderator/src/mod_add_community_view.rs @@ -14,14 +14,17 @@ use lemmy_db_schema::{ schema::{community, mod_add_community, person}, source::{community::Community, moderator::ModAddCommunity, person::Person}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type ModAddCommunityViewTuple = (ModAddCommunity, Option, Community, Person); impl ModAddCommunityView { - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; diff --git a/crates/db_views_moderator/src/mod_add_view.rs b/crates/db_views_moderator/src/mod_add_view.rs index ef408ce3a..13e090559 100644 --- a/crates/db_views_moderator/src/mod_add_view.rs +++ b/crates/db_views_moderator/src/mod_add_view.rs @@ -14,14 +14,17 @@ use lemmy_db_schema::{ schema::{mod_add, person}, source::{moderator::ModAdd, person::Person}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type ModAddViewTuple = (ModAdd, Option, Person); impl ModAddView { - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; diff --git a/crates/db_views_moderator/src/mod_ban_from_community_view.rs b/crates/db_views_moderator/src/mod_ban_from_community_view.rs index c7fb73956..5db3cd207 100644 --- a/crates/db_views_moderator/src/mod_ban_from_community_view.rs +++ b/crates/db_views_moderator/src/mod_ban_from_community_view.rs @@ -14,14 +14,17 @@ use lemmy_db_schema::{ schema::{community, mod_ban_from_community, person}, source::{community::Community, moderator::ModBanFromCommunity, person::Person}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type ModBanFromCommunityViewTuple = (ModBanFromCommunity, Option, Community, Person); impl ModBanFromCommunityView { - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); diff --git a/crates/db_views_moderator/src/mod_ban_view.rs b/crates/db_views_moderator/src/mod_ban_view.rs index 7bdf0dcf7..1ab173695 100644 --- a/crates/db_views_moderator/src/mod_ban_view.rs +++ b/crates/db_views_moderator/src/mod_ban_view.rs @@ -14,14 +14,17 @@ use lemmy_db_schema::{ schema::{mod_ban, person}, source::{moderator::ModBan, person::Person}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type ModBanViewTuple = (ModBan, Option, Person); impl ModBanView { - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; diff --git a/crates/db_views_moderator/src/mod_feature_post_view.rs b/crates/db_views_moderator/src/mod_feature_post_view.rs index 66bd4264f..b47ad9149 100644 --- a/crates/db_views_moderator/src/mod_feature_post_view.rs +++ b/crates/db_views_moderator/src/mod_feature_post_view.rs @@ -14,14 +14,17 @@ use lemmy_db_schema::{ schema::{community, mod_feature_post, person, post}, source::{community::Community, moderator::ModFeaturePost, person::Person, post::Post}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type ModFeaturePostViewTuple = (ModFeaturePost, Option, Post, Community); impl ModFeaturePostView { - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; diff --git a/crates/db_views_moderator/src/mod_hide_community_view.rs b/crates/db_views_moderator/src/mod_hide_community_view.rs index c2c6294bf..638089117 100644 --- a/crates/db_views_moderator/src/mod_hide_community_view.rs +++ b/crates/db_views_moderator/src/mod_hide_community_view.rs @@ -14,15 +14,18 @@ use lemmy_db_schema::{ schema::{community, mod_hide_community, person}, source::{community::Community, moderator::ModHideCommunity, person::Person}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type ModHideCommunityViewTuple = (ModHideCommunity, Option, Community); impl ModHideCommunityView { // Pass in mod_id as admin_id because only admins can do this action - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; diff --git a/crates/db_views_moderator/src/mod_lock_post_view.rs b/crates/db_views_moderator/src/mod_lock_post_view.rs index 15ff7855c..4865f886a 100644 --- a/crates/db_views_moderator/src/mod_lock_post_view.rs +++ b/crates/db_views_moderator/src/mod_lock_post_view.rs @@ -14,14 +14,17 @@ use lemmy_db_schema::{ schema::{community, mod_lock_post, person, post}, source::{community::Community, moderator::ModLockPost, person::Person, post::Post}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type ModLockPostViewTuple = (ModLockPost, Option, Post, Community); impl ModLockPostView { - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); diff --git a/crates/db_views_moderator/src/mod_remove_comment_view.rs b/crates/db_views_moderator/src/mod_remove_comment_view.rs index 0d33974b8..c296d4add 100644 --- a/crates/db_views_moderator/src/mod_remove_comment_view.rs +++ b/crates/db_views_moderator/src/mod_remove_comment_view.rs @@ -20,7 +20,7 @@ use lemmy_db_schema::{ post::Post, }, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type ModRemoveCommentViewTuple = ( @@ -33,8 +33,11 @@ type ModRemoveCommentViewTuple = ( ); impl ModRemoveCommentView { - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let person_alias_1 = diesel::alias!(lemmy_db_schema::schema::person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; diff --git a/crates/db_views_moderator/src/mod_remove_community_view.rs b/crates/db_views_moderator/src/mod_remove_community_view.rs index 50f99e528..2c84628a5 100644 --- a/crates/db_views_moderator/src/mod_remove_community_view.rs +++ b/crates/db_views_moderator/src/mod_remove_community_view.rs @@ -14,14 +14,17 @@ use lemmy_db_schema::{ schema::{community, mod_remove_community, person}, source::{community::Community, moderator::ModRemoveCommunity, person::Person}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type ModRemoveCommunityTuple = (ModRemoveCommunity, Option, Community); impl ModRemoveCommunityView { - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; let show_mod_names_expr = show_mod_names.as_sql::(); diff --git a/crates/db_views_moderator/src/mod_remove_post_view.rs b/crates/db_views_moderator/src/mod_remove_post_view.rs index fff5df466..19a3e5a88 100644 --- a/crates/db_views_moderator/src/mod_remove_post_view.rs +++ b/crates/db_views_moderator/src/mod_remove_post_view.rs @@ -14,14 +14,17 @@ use lemmy_db_schema::{ schema::{community, mod_remove_post, person, post}, source::{community::Community, moderator::ModRemovePost, person::Person, post::Post}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type ModRemovePostViewTuple = (ModRemovePost, Option, Post, Community); impl ModRemovePostView { - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); diff --git a/crates/db_views_moderator/src/mod_transfer_community_view.rs b/crates/db_views_moderator/src/mod_transfer_community_view.rs index 60da8e83f..6a3da279e 100644 --- a/crates/db_views_moderator/src/mod_transfer_community_view.rs +++ b/crates/db_views_moderator/src/mod_transfer_community_view.rs @@ -14,14 +14,17 @@ use lemmy_db_schema::{ schema::{community, mod_transfer_community, person}, source::{community::Community, moderator::ModTransferCommunity, person::Person}, traits::JoinView, - utils::{get_conn, limit_and_offset, DbPool}, + utils::{limit_and_offset, DbPool, GetConn}, }; type ModTransferCommunityViewTuple = (ModTransferCommunity, Option, Community, Person); impl ModTransferCommunityView { - pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + pub async fn list( + mut pool: &mut impl GetConn, + params: ModlogListParams, + ) -> Result, Error> { + let conn = &mut *pool.get_conn().await?; let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); diff --git a/crates/routes/src/feeds.rs b/crates/routes/src/feeds.rs index 2d894c683..caa33178d 100644 --- a/crates/routes/src/feeds.rs +++ b/crates/routes/src/feeds.rs @@ -6,7 +6,7 @@ use lemmy_db_schema::{ newtypes::LocalUserId, source::{community::Community, local_user::LocalUser, person::Person}, traits::{ApubActor, Crud}, - utils::DbPool, + utils::{DbPool, GetConn}, CommentSortType, ListingType, SortType, @@ -227,7 +227,7 @@ async fn get_feed( #[tracing::instrument(skip_all)] async fn get_feed_user( - pool: &DbPool, + mut pool: &mut impl GetConn, sort_type: &SortType, limit: &i64, page: &i64, @@ -262,7 +262,7 @@ async fn get_feed_user( #[tracing::instrument(skip_all)] async fn get_feed_community( - pool: &DbPool, + mut pool: &mut impl GetConn, sort_type: &SortType, limit: &i64, page: &i64, @@ -300,7 +300,7 @@ async fn get_feed_community( #[tracing::instrument(skip_all)] async fn get_feed_front( - pool: &DbPool, + mut pool: &mut impl GetConn, jwt_secret: &str, sort_type: &SortType, limit: &i64, @@ -341,7 +341,7 @@ async fn get_feed_front( #[tracing::instrument(skip_all)] async fn get_feed_inbox( - pool: &DbPool, + mut pool: &mut impl GetConn, jwt_secret: &str, jwt: &str, protocol_and_hostname: &str, diff --git a/src/code_migrations.rs b/src/code_migrations.rs index c69ce591c..33100d277 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -33,13 +33,16 @@ use lemmy_db_schema::{ site::{Site, SiteInsertForm, SiteUpdateForm}, }, traits::Crud, - utils::{get_conn, naive_now, DbPool}, + utils::{naive_now, DbPool, GetConn}, }; use lemmy_utils::{error::LemmyError, settings::structs::Settings}; use tracing::info; use url::Url; -pub async fn run_advanced_migrations(pool: &DbPool, settings: &Settings) -> Result<(), LemmyError> { +pub async fn run_advanced_migrations( + mut pool: &mut impl GetConn, + settings: &Settings, +) -> Result<(), LemmyError> { let protocol_and_hostname = &settings.get_protocol_and_hostname(); user_updates_2020_04_02(pool, protocol_and_hostname).await?; community_updates_2020_04_02(pool, protocol_and_hostname).await?; @@ -56,11 +59,11 @@ pub async fn run_advanced_migrations(pool: &DbPool, settings: &Settings) -> Resu } async fn user_updates_2020_04_02( - pool: &DbPool, + mut pool: &mut impl GetConn, protocol_and_hostname: &str, ) -> Result<(), LemmyError> { use lemmy_db_schema::schema::person::dsl::{actor_id, local, person}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; info!("Running user_updates_2020_04_02"); @@ -94,11 +97,11 @@ async fn user_updates_2020_04_02( } async fn community_updates_2020_04_02( - pool: &DbPool, + mut pool: &mut impl GetConn, protocol_and_hostname: &str, ) -> Result<(), LemmyError> { use lemmy_db_schema::schema::community::dsl::{actor_id, community, local}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; info!("Running community_updates_2020_04_02"); @@ -133,11 +136,11 @@ async fn community_updates_2020_04_02( } async fn post_updates_2020_04_03( - pool: &DbPool, + mut pool: &mut impl GetConn, protocol_and_hostname: &str, ) -> Result<(), LemmyError> { use lemmy_db_schema::schema::post::dsl::{ap_id, local, post}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; info!("Running post_updates_2020_04_03"); @@ -168,11 +171,11 @@ async fn post_updates_2020_04_03( } async fn comment_updates_2020_04_03( - pool: &DbPool, + mut pool: &mut impl GetConn, protocol_and_hostname: &str, ) -> Result<(), LemmyError> { use lemmy_db_schema::schema::comment::dsl::{ap_id, comment, local}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; info!("Running comment_updates_2020_04_03"); @@ -203,11 +206,11 @@ async fn comment_updates_2020_04_03( } async fn private_message_updates_2020_05_05( - pool: &DbPool, + mut pool: &mut impl GetConn, protocol_and_hostname: &str, ) -> Result<(), LemmyError> { use lemmy_db_schema::schema::private_message::dsl::{ap_id, local, private_message}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; info!("Running private_message_updates_2020_05_05"); @@ -240,11 +243,11 @@ async fn private_message_updates_2020_05_05( } async fn post_thumbnail_url_updates_2020_07_27( - pool: &DbPool, + mut pool: &mut impl GetConn, protocol_and_hostname: &str, ) -> Result<(), LemmyError> { use lemmy_db_schema::schema::post::dsl::{post, thumbnail_url}; - let conn = &mut get_conn(pool).await?; + let conn = &mut *pool.get_conn().await?; info!("Running post_thumbnail_url_updates_2020_07_27"); @@ -271,8 +274,8 @@ async fn post_thumbnail_url_updates_2020_07_27( /// We are setting inbox and follower URLs for local and remote actors alike, because for now /// all federated instances are also Lemmy and use the same URL scheme. -async fn apub_columns_2021_02_02(pool: &DbPool) -> Result<(), LemmyError> { - let conn = &mut get_conn(pool).await?; +async fn apub_columns_2021_02_02(mut pool: &mut impl GetConn) -> Result<(), LemmyError> { + let conn = &mut *pool.get_conn().await?; info!("Running apub_columns_2021_02_02"); { use lemmy_db_schema::schema::person::dsl::{inbox_url, person, shared_inbox_url}; @@ -329,7 +332,7 @@ async fn apub_columns_2021_02_02(pool: &DbPool) -> Result<(), LemmyError> { /// Before this point, there is only a single value in the site table which refers to the local /// Lemmy instance, so thats all we need to update. async fn instance_actor_2022_01_28( - pool: &DbPool, + mut pool: &mut impl GetConn, protocol_and_hostname: &str, ) -> Result<(), LemmyError> { info!("Running instance_actor_2021_09_29"); @@ -358,8 +361,8 @@ async fn instance_actor_2022_01_28( /// key field is empty, generate a new keypair. It would be possible to regenerate only the pubkey, /// but thats more complicated and has no benefit, as federation is already broken for these actors. /// https://github.com/LemmyNet/lemmy/issues/2347 -async fn regenerate_public_keys_2022_07_05(pool: &DbPool) -> Result<(), LemmyError> { - let conn = &mut get_conn(pool).await?; +async fn regenerate_public_keys_2022_07_05(mut pool: &mut impl GetConn) -> Result<(), LemmyError> { + let conn = &mut *pool.get_conn().await?; info!("Running regenerate_public_keys_2022_07_05"); { @@ -413,7 +416,7 @@ async fn regenerate_public_keys_2022_07_05(pool: &DbPool) -> Result<(), LemmyErr /// If a site already exists, the DB migration should generate a local_site row. /// This will only be run for brand new sites. async fn initialize_local_site_2022_10_10( - pool: &DbPool, + mut pool: &mut impl GetConn, settings: &Settings, ) -> Result<(), LemmyError> { info!("Running initialize_local_site_2022_10_10");