From 443a2a00a56d152bb7eb429efd0d29a78e21b163 Mon Sep 17 00:00:00 2001 From: dull b Date: Wed, 5 Jul 2023 06:33:57 +0000 Subject: [PATCH] Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. --- 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, 711 insertions(+), 1070 deletions(-) diff --git a/crates/api_common/src/context.rs b/crates/api_common/src/context.rs index 2d2eb7814..42fa74964 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) -> impl GetConn { + pub fn pool(&self) -> &DbPool { &self.pool } pub fn client(&self) -> &ClientWithMiddleware { diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index aa42d4c58..fd143ed90 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, GetConn}, + utils::DbPool, 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( - mut pool: &mut impl GetConn, + pool: &DbPool, 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( - mut pool: &mut impl GetConn, + pool: &DbPool, 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, mut pool: &mut impl GetConn) -> Result { +pub async fn get_post(post_id: PostId, pool: &DbPool) -> 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, mut pool: &mut impl GetConn) -> 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, - mut pool: &mut impl GetConn, + pool: &DbPool, ) -> 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, - mut pool: &mut impl GetConn, + pool: &DbPool, ) -> 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, - mut pool: &mut impl GetConn, + pool: &DbPool, ) -> 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, - mut pool: &mut impl GetConn, + pool: &DbPool, ) -> 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, - mut pool: &mut impl GetConn, + pool: &DbPool, ) -> 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, - mut pool: &mut impl GetConn, + pool: &DbPool, 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, - mut pool: &mut impl GetConn, + pool: &DbPool, 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, - mut pool: &mut impl GetConn, + pool: &DbPool, 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, - mut pool: &mut impl GetConn, + pool: &DbPool, 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, - mut pool: &mut impl GetConn, + pool: &DbPool, ) -> 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, - mut pool: &mut impl GetConn, + pool: &DbPool, 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, - mut pool: &mut impl GetConn, + pool: &DbPool, 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, - mut pool: &mut impl GetConn, + pool: &DbPool, 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, - mut pool: &mut impl GetConn, + pool: &DbPool, ) -> 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, - mut pool: &mut impl GetConn, + pool: &DbPool, 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 a8ec80b2f..a791ea40e 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, GetConn}, + utils::DbPool, }; use lemmy_db_views::structs::SiteView; use lemmy_utils::{error::LemmyError, utils::time::naive_from_unix}; @@ -118,10 +118,7 @@ impl SiteOrCommunity { } } -async fn generate_cc( - target: &SiteOrCommunity, - mut pool: &mut impl GetConn, -) -> Result, LemmyError> { +async fn generate_cc(target: &SiteOrCommunity, pool: &DbPool) -> 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 8377421ec..09689def1 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, - mut pool: &mut impl GetConn, + pool: &DbPool, ) -> Result, LemmyError> { use SearchableObjects::*; let removed_or_deleted; diff --git a/crates/apub/src/lib.rs b/crates/apub/src/lib.rs index 0fc4ac20a..a5bc41d1f 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, GetConn}, + utils::DbPool, }; 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( - mut pool: &mut impl GetConn, + pool: &DbPool, ) -> 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 f49f88273..088f84d0d 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, GetConn}, + utils::DbPool, }; 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( - mut pool: &mut impl GetConn, + pool: &DbPool, 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 097cefb0b..6cd27fbbd 100644 --- a/crates/apub/src/objects/instance.rs +++ b/crates/apub/src/objects/instance.rs @@ -195,9 +195,7 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object + C } } -pub(crate) async fn remote_instance_inboxes( - mut pool: &mut impl GetConn, -) -> Result, LemmyError> { +pub(crate) async fn remote_instance_inboxes(pool: &DbPool) -> 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 791ff6e0b..f35140a9b 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, GetConn}, + utils::DbPool, }; 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, - mut pool: &mut impl GetConn, + pool: &DbPool, ) -> 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, - mut pool: &mut impl GetConn, + pool: &DbPool, ) -> Result, LemmyError> { let mut langs = Vec::::new(); @@ -70,7 +70,7 @@ impl LanguageTag { pub(crate) async fn to_language_id_single( lang: Option, - mut pool: &mut impl GetConn, + pool: &DbPool, ) -> 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, - mut pool: &mut impl GetConn, + pool: &DbPool, ) -> 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 77cd8f0c2..5a5550a2e 100644 --- a/crates/db_schema/src/aggregates/comment_aggregates.rs +++ b/crates/db_schema/src/aggregates/comment_aggregates.rs @@ -2,25 +2,22 @@ use crate::{ aggregates::structs::CommentAggregates, newtypes::CommentId, schema::comment_aggregates, - utils::{functions::hot_rank, DbPool, GetConn}, + utils::{functions::hot_rank, get_conn, DbPool}, }; use diesel::{result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; impl CommentAggregates { - pub async fn read(mut pool: &mut impl GetConn, comment_id: CommentId) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read(pool: &DbPool, comment_id: CommentId) -> Result { + let conn = &mut get_conn(pool).await?; comment_aggregates::table .filter(comment_aggregates::comment_id.eq(comment_id)) .first::(conn) .await } - pub async fn update_hot_rank( - mut pool: &mut impl GetConn, - comment_id: CommentId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn update_hot_rank(pool: &DbPool, comment_id: CommentId) -> Result { + let conn = &mut get_conn(pool).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 b667bfaeb..2c2eaa781 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; impl CommunityAggregates { - pub async fn read(mut pool: &mut impl GetConn, community_id: CommunityId) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read(pool: &DbPool, community_id: CommunityId) -> Result { + let conn = &mut get_conn(pool).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 c900973e0..295f1bfbb 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; impl PersonAggregates { - pub async fn read(mut pool: &mut impl GetConn, person_id: PersonId) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read(pool: &DbPool, person_id: PersonId) -> Result { + let conn = &mut get_conn(pool).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 bcec04d03..5fe1aacff 100644 --- a/crates/db_schema/src/aggregates/person_post_aggregates.rs +++ b/crates/db_schema/src/aggregates/person_post_aggregates.rs @@ -3,17 +3,14 @@ use crate::{ diesel::BoolExpressionMethods, newtypes::{PersonId, PostId}, schema::person_post_aggregates::dsl::{person_id, person_post_aggregates, post_id}, - utils::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; impl PersonPostAggregates { - pub async fn upsert( - mut pool: &mut impl GetConn, - form: &PersonPostAggregatesForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn upsert(pool: &DbPool, form: &PersonPostAggregatesForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(person_post_aggregates) .values(form) .on_conflict((person_id, post_id)) @@ -22,12 +19,8 @@ impl PersonPostAggregates { .get_result::(conn) .await } - pub async fn read( - mut pool: &mut impl GetConn, - person_id_: PersonId, - post_id_: PostId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read(pool: &DbPool, person_id_: PersonId, post_id_: PostId) -> Result { + let conn = &mut get_conn(pool).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 dc09ced9f..176f694a7 100644 --- a/crates/db_schema/src/aggregates/post_aggregates.rs +++ b/crates/db_schema/src/aggregates/post_aggregates.rs @@ -2,25 +2,22 @@ use crate::{ aggregates::structs::PostAggregates, newtypes::PostId, schema::post_aggregates, - utils::{functions::hot_rank, DbPool, GetConn}, + utils::{functions::hot_rank, get_conn, DbPool}, }; use diesel::{result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; impl PostAggregates { - pub async fn read(mut pool: &mut impl GetConn, post_id: PostId) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read(pool: &DbPool, post_id: PostId) -> Result { + let conn = &mut get_conn(pool).await?; post_aggregates::table .filter(post_aggregates::post_id.eq(post_id)) .first::(conn) .await } - pub async fn update_hot_rank( - mut pool: &mut impl GetConn, - post_id: PostId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn update_hot_rank(pool: &DbPool, post_id: PostId) -> Result { + let conn = &mut get_conn(pool).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 359507cf9..719beb8f7 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::result::Error; use diesel_async::RunQueryDsl; impl SiteAggregates { - pub async fn read(mut pool: &mut impl GetConn) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read(pool: &DbPool) -> Result { + let conn = &mut get_conn(pool).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 055d074df..9187e736c 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; @@ -13,16 +13,13 @@ impl Crud for Activity { type InsertForm = ActivityInsertForm; type UpdateForm = ActivityUpdateForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, activity_id: i32) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn read(pool: &DbPool, activity_id: i32) -> Result { + let conn = &mut get_conn(pool).await?; activity.find(activity_id).first::(conn).await } - async fn create( - mut pool: &mut impl GetConn, - new_activity: &Self::InsertForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn create(pool: &DbPool, new_activity: &Self::InsertForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(activity) .values(new_activity) .get_result::(conn) @@ -30,18 +27,18 @@ impl Crud for Activity { } async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, activity_id: i32, new_activity: &Self::UpdateForm, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(activity.find(activity_id)) .set(new_activity) .get_result::(conn) .await } - async fn delete(mut pool: &mut impl GetConn, activity_id: i32) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn delete(pool: &DbPool, activity_id: i32) -> Result { + let conn = &mut get_conn(pool).await?; diesel::delete(activity.find(activity_id)) .execute(conn) .await @@ -49,11 +46,8 @@ impl Crud for Activity { } impl Activity { - pub async fn read_from_apub_id( - mut pool: &mut impl GetConn, - object_id: &DbUrl, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result { + let conn = &mut get_conn(pool).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 a3e0d7419..dbb9c70fe 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{ delete, @@ -37,7 +37,7 @@ pub const UNDETERMINED_ID: LanguageId = LanguageId(0); impl LocalUserLanguage { pub async fn read( - mut pool: &mut impl GetConn, + pool: &DbPool, 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 *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, language_ids: Vec, for_local_user_id: LocalUserId, ) -> Result<(), Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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(mut pool: &mut impl GetConn) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn read_local_raw(pool: &DbPool) -> Result, Error> { + let conn = &mut get_conn(pool).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 AsyncPgConnection, + conn: &mut PooledConnection, for_site_id: SiteId, ) -> Result, Error> { site_language::table @@ -141,22 +141,19 @@ impl SiteLanguage { .await } - pub async fn read( - mut pool: &mut impl GetConn, - for_site_id: SiteId, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn read(pool: &DbPool, for_site_id: SiteId) -> Result, Error> { + let conn = &mut get_conn(pool).await?; let langs = Self::read_raw(conn, for_site_id).await?; convert_read_languages(conn, langs).await } pub async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, language_ids: Vec, site: &Site, ) -> Result<(), Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; let for_site_id = site.id; let instance_id = site.instance_id; let lang_ids = convert_update_languages(conn, language_ids).await?; @@ -201,12 +198,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( - mut pool: &mut impl GetConn, + pool: &DbPool, 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 *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; if let Some(for_language_id) = for_language_id { let is_allowed = select(exists( @@ -258,7 +255,7 @@ impl CommunityLanguage { } async fn read_raw( - conn: &mut AsyncPgConnection, + conn: &mut PooledConnection, for_community_id: CommunityId, ) -> Result, Error> { use crate::schema::community_language::dsl::{community_id, community_language, language_id}; @@ -271,20 +268,20 @@ impl CommunityLanguage { } pub async fn read( - mut pool: &mut impl GetConn, + pool: &DbPool, for_community_id: CommunityId, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; let langs = Self::read_raw(conn, for_community_id).await?; convert_read_languages(conn, langs).await } pub async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, mut language_ids: Vec, for_community_id: CommunityId, ) -> Result<(), Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; if language_ids.is_empty() { language_ids = SiteLanguage::read_local_raw(pool).await?; } @@ -324,12 +321,12 @@ impl CommunityLanguage { } pub async fn default_post_language( - mut pool: &mut impl GetConn, + pool: &DbPool, 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 *pool.get_conn().await?; + let conn = &mut get_conn(pool).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)) @@ -399,9 +396,9 @@ mod tests { convert_read_languages, convert_update_languages, default_post_language, + get_conn, CommunityLanguage, DbPool, - GetConn, Language, LanguageId, LocalUserLanguage, @@ -422,7 +419,7 @@ mod tests { }; use serial_test::serial; - async fn test_langs1(mut pool: &mut impl GetConn) -> Vec { + async fn test_langs1(pool: &DbPool) -> Vec { vec![ Language::read_id_from_code(pool, Some("en")) .await @@ -438,7 +435,7 @@ mod tests { .unwrap(), ] } - async fn test_langs2(mut pool: &mut impl GetConn) -> Vec { + async fn test_langs2(pool: &DbPool) -> Vec { vec![ Language::read_id_from_code(pool, Some("fi")) .await @@ -451,7 +448,7 @@ mod tests { ] } - async fn create_test_site(mut pool: &mut impl GetConn) -> (Site, Instance) { + async fn create_test_site(pool: &DbPool) -> (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 50491569c..de5fac65e 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, DbPool, GetConn}, + utils::{functions::lower, get_conn, DbPool}, }; use diesel::{ delete, @@ -15,11 +15,8 @@ use diesel::{ use diesel_async::RunQueryDsl; impl CaptchaAnswer { - pub async fn insert( - mut pool: &mut impl GetConn, - captcha: &CaptchaAnswerForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn insert(pool: &DbPool, captcha: &CaptchaAnswerForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(captcha_answer) .values(captcha) @@ -27,11 +24,8 @@ impl CaptchaAnswer { .await } - pub async fn check_captcha( - mut pool: &mut impl GetConn, - to_check: CheckCaptchaAnswer, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn check_captcha(pool: &DbPool, to_check: CheckCaptchaAnswer) -> Result { + let conn = &mut get_conn(pool).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 a4289532a..ea66347db 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::{naive_now, DbPool, GetConn, DELETED_REPLACEMENT_TEXT}, + utils::{get_conn, naive_now, DbPool, 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( - mut pool: &mut impl GetConn, + pool: &DbPool, for_creator_id: PersonId, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, for_creator_id: PersonId, new_removed: bool, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, comment_form: &CommentInsertForm, parent_path: Option<&Ltree>, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; // Insert, to get the id let inserted_comment = insert_into(comment) @@ -123,11 +123,8 @@ where ca.comment_id = c.id" inserted_comment } } - pub async fn read_from_apub_id( - mut pool: &mut impl GetConn, - object_id: Url, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn read_from_apub_id(pool: &DbPool, object_id: Url) -> Result, Error> { + let conn = &mut get_conn(pool).await?; let object_id: DbUrl = object_id.into(); Ok( comment @@ -156,30 +153,27 @@ impl Crud for Comment { type InsertForm = CommentInsertForm; type UpdateForm = CommentUpdateForm; type IdType = CommentId; - async fn read(mut pool: &mut impl GetConn, comment_id: CommentId) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn read(pool: &DbPool, comment_id: CommentId) -> Result { + let conn = &mut get_conn(pool).await?; comment.find(comment_id).first::(conn).await } - async fn delete(mut pool: &mut impl GetConn, comment_id: CommentId) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn delete(pool: &DbPool, comment_id: CommentId) -> Result { + let conn = &mut get_conn(pool).await?; diesel::delete(comment.find(comment_id)).execute(conn).await } /// This is unimplemented, use [[Comment::create]] - async fn create( - _pool: &mut impl GetConn, - _comment_form: &Self::InsertForm, - ) -> Result { + async fn create(_pool: &DbPool, _comment_form: &Self::InsertForm) -> Result { unimplemented!(); } async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, comment_id: CommentId, comment_form: &Self::UpdateForm, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(comment.find(comment_id)) .set(comment_form) .get_result::(conn) @@ -191,12 +185,9 @@ impl Crud for Comment { impl Likeable for CommentLike { type Form = CommentLikeForm; type IdType = CommentId; - async fn like( - mut pool: &mut impl GetConn, - comment_like_form: &CommentLikeForm, - ) -> Result { + async fn like(pool: &DbPool, comment_like_form: &CommentLikeForm) -> Result { use crate::schema::comment_like::dsl::{comment_id, comment_like, person_id}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(comment_like) .values(comment_like_form) .on_conflict((comment_id, person_id)) @@ -206,12 +197,12 @@ impl Likeable for CommentLike { .await } async fn remove( - mut pool: &mut impl GetConn, + pool: &DbPool, person_id_: PersonId, comment_id_: CommentId, ) -> Result { use crate::schema::comment_like::dsl::{comment_id, comment_like, person_id}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::delete( comment_like .filter(comment_id.eq(comment_id_)) @@ -225,12 +216,9 @@ impl Likeable for CommentLike { #[async_trait] impl Saveable for CommentSaved { type Form = CommentSavedForm; - async fn save( - mut pool: &mut impl GetConn, - comment_saved_form: &CommentSavedForm, - ) -> Result { + async fn save(pool: &DbPool, comment_saved_form: &CommentSavedForm) -> Result { use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(comment_saved) .values(comment_saved_form) .on_conflict((comment_id, person_id)) @@ -239,12 +227,9 @@ impl Saveable for CommentSaved { .get_result::(conn) .await } - async fn unsave( - mut pool: &mut impl GetConn, - comment_saved_form: &CommentSavedForm, - ) -> Result { + async fn unsave(pool: &DbPool, comment_saved_form: &CommentSavedForm) -> Result { use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 309cc1763..2489c982f 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; @@ -13,22 +13,16 @@ impl Crud for CommentReply { type InsertForm = CommentReplyInsertForm; type UpdateForm = CommentReplyUpdateForm; type IdType = CommentReplyId; - async fn read( - mut pool: &mut impl GetConn, - comment_reply_id: CommentReplyId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn read(pool: &DbPool, comment_reply_id: CommentReplyId) -> Result { + let conn = &mut get_conn(pool).await?; comment_reply .find(comment_reply_id) .first::(conn) .await } - async fn create( - mut pool: &mut impl GetConn, - comment_reply_form: &Self::InsertForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn create(pool: &DbPool, comment_reply_form: &Self::InsertForm) -> Result { + let conn = &mut get_conn(pool).await?; // since the return here isnt utilized, we dont need to do an update // but get_result doesnt return the existing row here @@ -42,11 +36,11 @@ impl Crud for CommentReply { } async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, comment_reply_id: CommentReplyId, comment_reply_form: &Self::UpdateForm, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(comment_reply.find(comment_reply_id)) .set(comment_reply_form) .get_result::(conn) @@ -56,10 +50,10 @@ impl Crud for CommentReply { impl CommentReply { pub async fn mark_all_as_read( - mut pool: &mut impl GetConn, + pool: &DbPool, for_recipient_id: PersonId, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update( comment_reply .filter(recipient_id.eq(for_recipient_id)) @@ -70,11 +64,8 @@ impl CommentReply { .await } - pub async fn read_by_comment( - mut pool: &mut impl GetConn, - for_comment_id: CommentId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read_by_comment(pool: &DbPool, for_comment_id: CommentId) -> Result { + let conn = &mut get_conn(pool).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 9741c91b3..18cf83a72 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::{naive_now, DbPool, GetConn}, + utils::{get_conn, naive_now, DbPool}, }; use diesel::{ dsl::{insert_into, update}, @@ -21,11 +21,8 @@ impl Reportable for CommentReport { /// /// * `conn` - the postgres connection /// * `comment_report_form` - the filled CommentReportForm to insert - async fn report( - mut pool: &mut impl GetConn, - comment_report_form: &CommentReportForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn report(pool: &DbPool, comment_report_form: &CommentReportForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(comment_report) .values(comment_report_form) .get_result::(conn) @@ -38,11 +35,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( - mut pool: &mut impl GetConn, + pool: &DbPool, report_id_: Self::IdType, by_resolver_id: PersonId, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; update(comment_report.find(report_id_)) .set(( resolved.eq(true), @@ -59,11 +56,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( - mut pool: &mut impl GetConn, + pool: &DbPool, report_id_: Self::IdType, by_resolver_id: PersonId, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 67d2b9c25..ad9e6d47d 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, DbPool, GetConn}, + utils::{functions::lower, get_conn, DbPool}, 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(mut pool: &mut impl GetConn, community_id: CommunityId) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn read(pool: &DbPool, community_id: CommunityId) -> Result { + let conn = &mut get_conn(pool).await?; community::table .find(community_id) .first::(conn) .await } - async fn delete(mut pool: &mut impl GetConn, community_id: CommunityId) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn delete(pool: &DbPool, community_id: CommunityId) -> Result { + let conn = &mut get_conn(pool).await?; diesel::delete(community::table.find(community_id)) .execute(conn) .await } - async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, community_id: CommunityId, form: &Self::UpdateForm, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, community_moderator_form: &CommunityModeratorForm, ) -> Result { use crate::schema::community_moderator::dsl::community_moderator; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(community_moderator) .values(community_moderator_form) .get_result::(conn) @@ -95,11 +95,11 @@ impl Joinable for CommunityModerator { } async fn leave( - mut pool: &mut impl GetConn, + pool: &DbPool, community_moderator_form: &CommunityModeratorForm, ) -> Result { use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, url: &DbUrl, ) -> Result<(Community, CollectionType), Error> { use crate::schema::community::dsl::{featured_url, moderators_url}; use CollectionType::*; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, for_community_id: CommunityId, ) -> Result { use crate::schema::community_moderator::dsl::{community_id, community_moderator}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, for_person_id: PersonId, ) -> Result { use crate::schema::community_moderator::dsl::{community_moderator, person_id}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::delete(community_moderator.filter(person_id.eq(for_person_id))) .execute(conn) .await } pub async fn get_person_moderated_communities( - mut pool: &mut impl GetConn, + pool: &DbPool, for_person_id: PersonId, ) -> Result, Error> { use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, community_person_ban_form: &CommunityPersonBanForm, ) -> Result { use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, community_person_ban_form: &CommunityPersonBanForm, ) -> Result { use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::delete( community_person_ban .filter(community_id.eq(community_person_ban_form.community_id)) @@ -233,12 +233,9 @@ impl CommunityFollower { #[async_trait] impl Followable for CommunityFollower { type Form = CommunityFollowerForm; - async fn follow( - mut pool: &mut impl GetConn, - form: &CommunityFollowerForm, - ) -> Result { + async fn follow(pool: &DbPool, form: &CommunityFollowerForm) -> Result { use crate::schema::community_follower::dsl::{community_follower, community_id, person_id}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(community_follower) .values(form) .on_conflict((community_id, person_id)) @@ -248,7 +245,7 @@ impl Followable for CommunityFollower { .await } async fn follow_accepted( - mut pool: &mut impl GetConn, + pool: &DbPool, community_id_: CommunityId, person_id_: PersonId, ) -> Result { @@ -258,7 +255,7 @@ impl Followable for CommunityFollower { pending, person_id, }; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update( community_follower .filter(community_id.eq(community_id_)) @@ -268,12 +265,9 @@ impl Followable for CommunityFollower { .get_result::(conn) .await } - async fn unfollow( - mut pool: &mut impl GetConn, - form: &CommunityFollowerForm, - ) -> Result { + async fn unfollow(pool: &DbPool, form: &CommunityFollowerForm) -> Result { use crate::schema::community_follower::dsl::{community_follower, community_id, person_id}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::delete( community_follower .filter(community_id.eq(&form.community_id)) @@ -286,11 +280,8 @@ impl Followable for CommunityFollower { #[async_trait] impl ApubActor for Community { - async fn read_from_apub_id( - mut pool: &mut impl GetConn, - object_id: &DbUrl, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result, Error> { + let conn = &mut get_conn(pool).await?; Ok( community::table .filter(community::actor_id.eq(object_id)) @@ -302,11 +293,11 @@ impl ApubActor for Community { } async fn read_from_name( - mut pool: &mut impl GetConn, + pool: &DbPool, community_name: &str, include_deleted: bool, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; let mut q = community::table .into_boxed() .filter(community::local.eq(true)) @@ -320,11 +311,11 @@ impl ApubActor for Community { } async fn read_from_name_and_domain( - mut pool: &mut impl GetConn, + pool: &DbPool, community_name: &str, for_domain: &str, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 56054e236..c1f35e625 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; @@ -10,11 +10,8 @@ use diesel_async::RunQueryDsl; #[async_trait] impl Blockable for CommunityBlock { type Form = CommunityBlockForm; - async fn block( - mut pool: &mut impl GetConn, - community_block_form: &Self::Form, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn block(pool: &DbPool, community_block_form: &Self::Form) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(community_block) .values(community_block_form) .on_conflict((person_id, community_id)) @@ -23,11 +20,8 @@ impl Blockable for CommunityBlock { .get_result::(conn) .await } - async fn unblock( - mut pool: &mut impl GetConn, - community_block_form: &Self::Form, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn unblock(pool: &DbPool, community_block_form: &Self::Form) -> Result { + let conn = &mut get_conn(pool).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 081f2ac5a..cce35dfc7 100644 --- a/crates/db_schema/src/impls/custom_emoji.rs +++ b/crates/db_schema/src/impls/custom_emoji.rs @@ -8,38 +8,32 @@ use crate::{ custom_emoji::{CustomEmoji, CustomEmojiInsertForm, CustomEmojiUpdateForm}, custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm}, }, - utils::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; impl CustomEmoji { - pub async fn create( - mut pool: &mut impl GetConn, - form: &CustomEmojiInsertForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn create(pool: &DbPool, form: &CustomEmojiInsertForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(custom_emoji) .values(form) .get_result::(conn) .await } pub async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, emoji_id: CustomEmojiId, form: &CustomEmojiUpdateForm, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(custom_emoji.find(emoji_id)) .set(form) .get_result::(conn) .await } - pub async fn delete( - mut pool: &mut impl GetConn, - emoji_id: CustomEmojiId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn delete(pool: &DbPool, emoji_id: CustomEmojiId) -> Result { + let conn = &mut get_conn(pool).await?; diesel::delete(custom_emoji.find(emoji_id)) .execute(conn) .await @@ -48,20 +42,17 @@ impl CustomEmoji { impl CustomEmojiKeyword { pub async fn create( - mut pool: &mut impl GetConn, + pool: &DbPool, form: Vec, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(custom_emoji_keyword) .values(form) .get_results::(conn) .await } - pub async fn delete( - mut pool: &mut impl GetConn, - emoji_id: CustomEmojiId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn delete(pool: &DbPool, emoji_id: CustomEmojiId) -> Result { + let conn = &mut get_conn(pool).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 2d58404e0..af19bbba0 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{ dsl::{now, IntervalDsl}, @@ -19,19 +19,16 @@ use diesel::{ use diesel_async::RunQueryDsl; impl EmailVerification { - pub async fn create( - mut pool: &mut impl GetConn, - form: &EmailVerificationForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn create(pool: &DbPool, form: &EmailVerificationForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(email_verification) .values(form) .get_result::(conn) .await } - pub async fn read_for_token(mut pool: &mut impl GetConn, token: &str) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read_for_token(pool: &DbPool, token: &str) -> Result { + let conn = &mut get_conn(pool).await?; email_verification .filter(verification_token.eq(token)) .filter(published.gt(now - 7.days())) @@ -39,10 +36,10 @@ impl EmailVerification { .await } pub async fn delete_old_tokens_for_local_user( - mut pool: &mut impl GetConn, + pool: &DbPool, local_user_id_: LocalUserId, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 1b03e81c1..c71ffd1cf 100644 --- a/crates/db_schema/src/impls/federation_allowlist.rs +++ b/crates/db_schema/src/impls/federation_allowlist.rs @@ -4,17 +4,14 @@ use crate::{ federation_allowlist::{FederationAllowList, FederationAllowListForm}, instance::Instance, }, - utils::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{dsl::insert_into, result::Error}; use diesel_async::{AsyncPgConnection, RunQueryDsl}; impl FederationAllowList { - pub async fn replace( - mut pool: &mut impl GetConn, - list_opt: Option>, - ) -> Result<(), Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn replace(pool: &DbPool, list_opt: Option>) -> Result<(), Error> { + let conn = &mut get_conn(pool).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 bf596321a..917bf57a3 100644 --- a/crates/db_schema/src/impls/federation_blocklist.rs +++ b/crates/db_schema/src/impls/federation_blocklist.rs @@ -4,17 +4,14 @@ use crate::{ federation_blocklist::{FederationBlockList, FederationBlockListForm}, instance::Instance, }, - utils::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{dsl::insert_into, result::Error}; use diesel_async::{AsyncPgConnection, RunQueryDsl}; impl FederationBlockList { - pub async fn replace( - mut pool: &mut impl GetConn, - list_opt: Option>, - ) -> Result<(), Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn replace(pool: &DbPool, list_opt: Option>) -> Result<(), Error> { + let conn = &mut get_conn(pool).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 f999e6fee..e5a8caba3 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::{naive_now, DbPool, GetConn}, + utils::{get_conn, naive_now, DbPool}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::{AsyncPgConnection, RunQueryDsl}; @@ -42,26 +42,23 @@ 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(mut pool: &mut impl GetConn, domain: String) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read_or_create(pool: &DbPool, domain: String) -> Result { + let conn = &mut get_conn(pool).await?; Self::read_or_create_with_conn(conn, domain).await } - pub async fn delete( - mut pool: &mut impl GetConn, - instance_id: InstanceId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn delete(pool: &DbPool, instance_id: InstanceId) -> Result { + let conn = &mut get_conn(pool).await?; diesel::delete(instance::table.find(instance_id)) .execute(conn) .await } #[cfg(test)] - pub async fn delete_all(mut pool: &mut impl GetConn) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn delete_all(pool: &DbPool) -> Result { + let conn = &mut get_conn(pool).await?; diesel::delete(instance::table).execute(conn).await } - pub async fn allowlist(mut pool: &mut impl GetConn) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn allowlist(pool: &DbPool) -> Result, Error> { + let conn = &mut get_conn(pool).await?; instance::table .inner_join(federation_allowlist::table) .select(instance::all_columns) @@ -69,8 +66,8 @@ impl Instance { .await } - pub async fn blocklist(mut pool: &mut impl GetConn) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn blocklist(pool: &DbPool) -> Result, Error> { + let conn = &mut get_conn(pool).await?; instance::table .inner_join(federation_blocklist::table) .select(instance::all_columns) @@ -78,8 +75,8 @@ impl Instance { .await } - pub async fn linked(mut pool: &mut impl GetConn) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn linked(pool: &DbPool) -> Result, Error> { + let conn = &mut get_conn(pool).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 0d2aa0785..da9e0ca9d 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{result::Error, QueryDsl}; use diesel_async::{AsyncPgConnection, RunQueryDsl}; impl Language { - pub async fn read_all(mut pool: &mut impl GetConn) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn read_all(pool: &DbPool) -> Result, Error> { + let conn = &mut get_conn(pool).await?; Self::read_all_conn(conn).await } @@ -18,21 +18,18 @@ impl Language { language.load::(conn).await } - pub async fn read_from_id( - mut pool: &mut impl GetConn, - id_: LanguageId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read_from_id(pool: &DbPool, id_: LanguageId) -> Result { + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, code_: Option<&str>, ) -> Result, Error> { if let Some(code_) = code_ { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 e5ca31448..b9e920d15 100644 --- a/crates/db_schema/src/impls/local_site.rs +++ b/crates/db_schema/src/impls/local_site.rs @@ -1,38 +1,32 @@ use crate::{ schema::local_site::dsl::local_site, source::local_site::{LocalSite, LocalSiteInsertForm, LocalSiteUpdateForm}, - utils::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{dsl::insert_into, result::Error}; use diesel_async::RunQueryDsl; impl LocalSite { - pub async fn create( - mut pool: &mut impl GetConn, - form: &LocalSiteInsertForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn create(pool: &DbPool, form: &LocalSiteInsertForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(local_site) .values(form) .get_result::(conn) .await } - pub async fn read(mut pool: &mut impl GetConn) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read(pool: &DbPool) -> Result { + let conn = &mut get_conn(pool).await?; local_site.first::(conn).await } - pub async fn update( - mut pool: &mut impl GetConn, - form: &LocalSiteUpdateForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn update(pool: &DbPool, form: &LocalSiteUpdateForm) -> Result { + let conn = &mut get_conn(pool).await?; diesel::update(local_site) .set(form) .get_result::(conn) .await } - pub async fn delete(mut pool: &mut impl GetConn) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn delete(pool: &DbPool) -> Result { + let conn = &mut get_conn(pool).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 48fe95338..b1af5f869 100644 --- a/crates/db_schema/src/impls/local_site_rate_limit.rs +++ b/crates/db_schema/src/impls/local_site_rate_limit.rs @@ -5,36 +5,30 @@ use crate::{ LocalSiteRateLimitInsertForm, LocalSiteRateLimitUpdateForm, }, - utils::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{dsl::insert_into, result::Error}; use diesel_async::RunQueryDsl; impl LocalSiteRateLimit { - pub async fn read(mut pool: &mut impl GetConn) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read(pool: &DbPool) -> Result { + let conn = &mut get_conn(pool).await?; local_site_rate_limit::table.first::(conn).await } - pub async fn create( - mut pool: &mut impl GetConn, - form: &LocalSiteRateLimitInsertForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn create(pool: &DbPool, form: &LocalSiteRateLimitInsertForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(local_site_rate_limit::table) .values(form) .get_result::(conn) .await } - pub async fn update( - mut pool: &mut impl GetConn, - form: &LocalSiteRateLimitUpdateForm, - ) -> Result<(), Error> { + pub async fn update(pool: &DbPool, 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 *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 992121f27..c8ae23627 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::{naive_now, DbPool, GetConn}, + utils::{get_conn, naive_now, DbPool}, }; 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( - mut pool: &mut impl GetConn, + pool: &DbPool, local_user_id: LocalUserId, new_password: &str, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; let password_hash = hash(new_password, DEFAULT_COST).expect("Couldn't hash password"); diesel::update(local_user.find(local_user_id)) @@ -37,10 +37,8 @@ impl LocalUser { .await } - pub async fn set_all_users_email_verified( - mut pool: &mut impl GetConn, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn set_all_users_email_verified(pool: &DbPool) -> Result, Error> { + let conn = &mut get_conn(pool).await?; diesel::update(local_user) .set(email_verified.eq(true)) .get_results::(conn) @@ -48,18 +46,18 @@ impl LocalUser { } pub async fn set_all_users_registration_applications_accepted( - mut pool: &mut impl GetConn, + pool: &DbPool, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(local_user) .set(accepted_application.eq(true)) .get_results::(conn) .await } - pub async fn is_email_taken(mut pool: &mut impl GetConn, email_: &str) -> Result { + pub async fn is_email_taken(pool: &DbPool, email_: &str) -> Result { use diesel::dsl::{exists, select}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; select(exists(local_user.filter(email.eq(email_)))) .get_result(conn) .await @@ -71,18 +69,18 @@ impl Crud for LocalUser { type InsertForm = LocalUserInsertForm; type UpdateForm = LocalUserUpdateForm; type IdType = LocalUserId; - async fn read(mut pool: &mut impl GetConn, local_user_id: LocalUserId) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn read(pool: &DbPool, local_user_id: LocalUserId) -> Result { + let conn = &mut get_conn(pool).await?; local_user.find(local_user_id).first::(conn).await } - async fn delete(mut pool: &mut impl GetConn, local_user_id: LocalUserId) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn delete(pool: &DbPool, local_user_id: LocalUserId) -> Result { + let conn = &mut get_conn(pool).await?; diesel::delete(local_user.find(local_user_id)) .execute(conn) .await } - async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { + let conn = &mut get_conn(pool).await?; let mut form_with_encrypted_password = form.clone(); let password_hash = hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password"); @@ -106,11 +104,11 @@ impl Crud for LocalUser { Ok(local_user_) } async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, local_user_id: LocalUserId, form: &Self::UpdateForm, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 11df68e6e..ab8398cf3 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{dsl::insert_into, result::Error, QueryDsl}; use diesel_async::RunQueryDsl; @@ -42,28 +42,24 @@ impl Crud for ModRemovePost { type InsertForm = ModRemovePostForm; type UpdateForm = ModRemovePostForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::mod_remove_post::dsl::mod_remove_post; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; mod_remove_post.find(from_id).first::(conn).await } - async fn create(mut pool: &mut impl GetConn, form: &ModRemovePostForm) -> Result { + async fn create(pool: &DbPool, form: &ModRemovePostForm) -> Result { use crate::schema::mod_remove_post::dsl::mod_remove_post; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(mod_remove_post) .values(form) .get_result::(conn) .await } - async fn update( - mut pool: &mut impl GetConn, - from_id: i32, - form: &ModRemovePostForm, - ) -> Result { + async fn update(pool: &DbPool, from_id: i32, form: &ModRemovePostForm) -> Result { use crate::schema::mod_remove_post::dsl::mod_remove_post; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(mod_remove_post.find(from_id)) .set(form) .get_result::(conn) @@ -76,28 +72,24 @@ impl Crud for ModLockPost { type InsertForm = ModLockPostForm; type UpdateForm = ModLockPostForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::mod_lock_post::dsl::mod_lock_post; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; mod_lock_post.find(from_id).first::(conn).await } - async fn create(mut pool: &mut impl GetConn, form: &ModLockPostForm) -> Result { + async fn create(pool: &DbPool, form: &ModLockPostForm) -> Result { use crate::schema::mod_lock_post::dsl::mod_lock_post; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(mod_lock_post) .values(form) .get_result::(conn) .await } - async fn update( - mut pool: &mut impl GetConn, - from_id: i32, - form: &ModLockPostForm, - ) -> Result { + async fn update(pool: &DbPool, from_id: i32, form: &ModLockPostForm) -> Result { use crate::schema::mod_lock_post::dsl::mod_lock_post; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(mod_lock_post.find(from_id)) .set(form) .get_result::(conn) @@ -110,28 +102,24 @@ impl Crud for ModFeaturePost { type InsertForm = ModFeaturePostForm; type UpdateForm = ModFeaturePostForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::mod_feature_post::dsl::mod_feature_post; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; mod_feature_post.find(from_id).first::(conn).await } - async fn create(mut pool: &mut impl GetConn, form: &ModFeaturePostForm) -> Result { + async fn create(pool: &DbPool, form: &ModFeaturePostForm) -> Result { use crate::schema::mod_feature_post::dsl::mod_feature_post; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(mod_feature_post) .values(form) .get_result::(conn) .await } - async fn update( - mut pool: &mut impl GetConn, - from_id: i32, - form: &ModFeaturePostForm, - ) -> Result { + async fn update(pool: &DbPool, from_id: i32, form: &ModFeaturePostForm) -> Result { use crate::schema::mod_feature_post::dsl::mod_feature_post; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(mod_feature_post.find(from_id)) .set(form) .get_result::(conn) @@ -144,28 +132,24 @@ impl Crud for ModRemoveComment { type InsertForm = ModRemoveCommentForm; type UpdateForm = ModRemoveCommentForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::mod_remove_comment::dsl::mod_remove_comment; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; mod_remove_comment.find(from_id).first::(conn).await } - async fn create(mut pool: &mut impl GetConn, form: &ModRemoveCommentForm) -> Result { + async fn create(pool: &DbPool, form: &ModRemoveCommentForm) -> Result { use crate::schema::mod_remove_comment::dsl::mod_remove_comment; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(mod_remove_comment) .values(form) .get_result::(conn) .await } - async fn update( - mut pool: &mut impl GetConn, - from_id: i32, - form: &ModRemoveCommentForm, - ) -> Result { + async fn update(pool: &DbPool, from_id: i32, form: &ModRemoveCommentForm) -> Result { use crate::schema::mod_remove_comment::dsl::mod_remove_comment; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(mod_remove_comment.find(from_id)) .set(form) .get_result::(conn) @@ -178,18 +162,15 @@ impl Crud for ModRemoveCommunity { type InsertForm = ModRemoveCommunityForm; type UpdateForm = ModRemoveCommunityForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::mod_remove_community::dsl::mod_remove_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; mod_remove_community.find(from_id).first::(conn).await } - async fn create( - mut pool: &mut impl GetConn, - form: &ModRemoveCommunityForm, - ) -> Result { + async fn create(pool: &DbPool, form: &ModRemoveCommunityForm) -> Result { use crate::schema::mod_remove_community::dsl::mod_remove_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(mod_remove_community) .values(form) .get_result::(conn) @@ -197,12 +178,12 @@ impl Crud for ModRemoveCommunity { } async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, from_id: i32, form: &ModRemoveCommunityForm, ) -> Result { use crate::schema::mod_remove_community::dsl::mod_remove_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(mod_remove_community.find(from_id)) .set(form) .get_result::(conn) @@ -215,21 +196,18 @@ impl Crud for ModBanFromCommunity { type InsertForm = ModBanFromCommunityForm; type UpdateForm = ModBanFromCommunityForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; mod_ban_from_community .find(from_id) .first::(conn) .await } - async fn create( - mut pool: &mut impl GetConn, - form: &ModBanFromCommunityForm, - ) -> Result { + async fn create(pool: &DbPool, form: &ModBanFromCommunityForm) -> Result { use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(mod_ban_from_community) .values(form) .get_result::(conn) @@ -237,12 +215,12 @@ impl Crud for ModBanFromCommunity { } async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, from_id: i32, form: &ModBanFromCommunityForm, ) -> Result { use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(mod_ban_from_community.find(from_id)) .set(form) .get_result::(conn) @@ -255,28 +233,24 @@ impl Crud for ModBan { type InsertForm = ModBanForm; type UpdateForm = ModBanForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::mod_ban::dsl::mod_ban; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; mod_ban.find(from_id).first::(conn).await } - async fn create(mut pool: &mut impl GetConn, form: &ModBanForm) -> Result { + async fn create(pool: &DbPool, form: &ModBanForm) -> Result { use crate::schema::mod_ban::dsl::mod_ban; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(mod_ban) .values(form) .get_result::(conn) .await } - async fn update( - mut pool: &mut impl GetConn, - from_id: i32, - form: &ModBanForm, - ) -> Result { + async fn update(pool: &DbPool, from_id: i32, form: &ModBanForm) -> Result { use crate::schema::mod_ban::dsl::mod_ban; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(mod_ban.find(from_id)) .set(form) .get_result::(conn) @@ -290,28 +264,24 @@ impl Crud for ModHideCommunity { type UpdateForm = ModHideCommunityForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::mod_hide_community::dsl::mod_hide_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; mod_hide_community.find(from_id).first::(conn).await } - async fn create(mut pool: &mut impl GetConn, form: &ModHideCommunityForm) -> Result { + async fn create(pool: &DbPool, form: &ModHideCommunityForm) -> Result { use crate::schema::mod_hide_community::dsl::mod_hide_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(mod_hide_community) .values(form) .get_result::(conn) .await } - async fn update( - mut pool: &mut impl GetConn, - from_id: i32, - form: &ModHideCommunityForm, - ) -> Result { + async fn update(pool: &DbPool, from_id: i32, form: &ModHideCommunityForm) -> Result { use crate::schema::mod_hide_community::dsl::mod_hide_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(mod_hide_community.find(from_id)) .set(form) .get_result::(conn) @@ -324,28 +294,24 @@ impl Crud for ModAddCommunity { type InsertForm = ModAddCommunityForm; type UpdateForm = ModAddCommunityForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::mod_add_community::dsl::mod_add_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; mod_add_community.find(from_id).first::(conn).await } - async fn create(mut pool: &mut impl GetConn, form: &ModAddCommunityForm) -> Result { + async fn create(pool: &DbPool, form: &ModAddCommunityForm) -> Result { use crate::schema::mod_add_community::dsl::mod_add_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(mod_add_community) .values(form) .get_result::(conn) .await } - async fn update( - mut pool: &mut impl GetConn, - from_id: i32, - form: &ModAddCommunityForm, - ) -> Result { + async fn update(pool: &DbPool, from_id: i32, form: &ModAddCommunityForm) -> Result { use crate::schema::mod_add_community::dsl::mod_add_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(mod_add_community.find(from_id)) .set(form) .get_result::(conn) @@ -358,21 +324,18 @@ impl Crud for ModTransferCommunity { type InsertForm = ModTransferCommunityForm; type UpdateForm = ModTransferCommunityForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::mod_transfer_community::dsl::mod_transfer_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; mod_transfer_community .find(from_id) .first::(conn) .await } - async fn create( - mut pool: &mut impl GetConn, - form: &ModTransferCommunityForm, - ) -> Result { + async fn create(pool: &DbPool, form: &ModTransferCommunityForm) -> Result { use crate::schema::mod_transfer_community::dsl::mod_transfer_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(mod_transfer_community) .values(form) .get_result::(conn) @@ -380,12 +343,12 @@ impl Crud for ModTransferCommunity { } async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, from_id: i32, form: &ModTransferCommunityForm, ) -> Result { use crate::schema::mod_transfer_community::dsl::mod_transfer_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(mod_transfer_community.find(from_id)) .set(form) .get_result::(conn) @@ -398,28 +361,24 @@ impl Crud for ModAdd { type InsertForm = ModAddForm; type UpdateForm = ModAddForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::mod_add::dsl::mod_add; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; mod_add.find(from_id).first::(conn).await } - async fn create(mut pool: &mut impl GetConn, form: &ModAddForm) -> Result { + async fn create(pool: &DbPool, form: &ModAddForm) -> Result { use crate::schema::mod_add::dsl::mod_add; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(mod_add) .values(form) .get_result::(conn) .await } - async fn update( - mut pool: &mut impl GetConn, - from_id: i32, - form: &ModAddForm, - ) -> Result { + async fn update(pool: &DbPool, from_id: i32, form: &ModAddForm) -> Result { use crate::schema::mod_add::dsl::mod_add; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(mod_add.find(from_id)) .set(form) .get_result::(conn) @@ -432,28 +391,24 @@ impl Crud for AdminPurgePerson { type InsertForm = AdminPurgePersonForm; type UpdateForm = AdminPurgePersonForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::admin_purge_person::dsl::admin_purge_person; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; admin_purge_person.find(from_id).first::(conn).await } - async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { + async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { use crate::schema::admin_purge_person::dsl::admin_purge_person; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(admin_purge_person) .values(form) .get_result::(conn) .await } - async fn update( - mut pool: &mut impl GetConn, - from_id: i32, - form: &Self::InsertForm, - ) -> Result { + async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result { use crate::schema::admin_purge_person::dsl::admin_purge_person; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(admin_purge_person.find(from_id)) .set(form) .get_result::(conn) @@ -466,31 +421,27 @@ impl Crud for AdminPurgeCommunity { type InsertForm = AdminPurgeCommunityForm; type UpdateForm = AdminPurgeCommunityForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::admin_purge_community::dsl::admin_purge_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; admin_purge_community .find(from_id) .first::(conn) .await } - async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { + async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { use crate::schema::admin_purge_community::dsl::admin_purge_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(admin_purge_community) .values(form) .get_result::(conn) .await } - async fn update( - mut pool: &mut impl GetConn, - from_id: i32, - form: &Self::InsertForm, - ) -> Result { + async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result { use crate::schema::admin_purge_community::dsl::admin_purge_community; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(admin_purge_community.find(from_id)) .set(form) .get_result::(conn) @@ -503,28 +454,24 @@ impl Crud for AdminPurgePost { type InsertForm = AdminPurgePostForm; type UpdateForm = AdminPurgePostForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::admin_purge_post::dsl::admin_purge_post; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; admin_purge_post.find(from_id).first::(conn).await } - async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { + async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { use crate::schema::admin_purge_post::dsl::admin_purge_post; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(admin_purge_post) .values(form) .get_result::(conn) .await } - async fn update( - mut pool: &mut impl GetConn, - from_id: i32, - form: &Self::InsertForm, - ) -> Result { + async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result { use crate::schema::admin_purge_post::dsl::admin_purge_post; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(admin_purge_post.find(from_id)) .set(form) .get_result::(conn) @@ -537,28 +484,24 @@ impl Crud for AdminPurgeComment { type InsertForm = AdminPurgeCommentForm; type UpdateForm = AdminPurgeCommentForm; type IdType = i32; - async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result { + async fn read(pool: &DbPool, from_id: i32) -> Result { use crate::schema::admin_purge_comment::dsl::admin_purge_comment; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; admin_purge_comment.find(from_id).first::(conn).await } - async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { + async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { use crate::schema::admin_purge_comment::dsl::admin_purge_comment; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(admin_purge_comment) .values(form) .get_result::(conn) .await } - async fn update( - mut pool: &mut impl GetConn, - from_id: i32, - form: &Self::InsertForm, - ) -> Result { + async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result { use crate::schema::admin_purge_comment::dsl::admin_purge_comment; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 b58312500..85ad4cf01 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{ dsl::{insert_into, now, IntervalDsl}, @@ -24,32 +24,26 @@ impl Crud for PasswordResetRequest { type InsertForm = PasswordResetRequestForm; type UpdateForm = PasswordResetRequestForm; type IdType = i32; - async fn read( - mut pool: &mut impl GetConn, - password_reset_request_id: i32, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn read(pool: &DbPool, password_reset_request_id: i32) -> Result { + let conn = &mut get_conn(pool).await?; password_reset_request .find(password_reset_request_id) .first::(conn) .await } - async fn create( - mut pool: &mut impl GetConn, - form: &PasswordResetRequestForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn create(pool: &DbPool, form: &PasswordResetRequestForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(password_reset_request) .values(form) .get_result::(conn) .await } async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, password_reset_request_id: i32, form: &PasswordResetRequestForm, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(password_reset_request.find(password_reset_request_id)) .set(form) .get_result::(conn) @@ -59,7 +53,7 @@ impl Crud for PasswordResetRequest { impl PasswordResetRequest { pub async fn create_token( - mut pool: &mut impl GetConn, + pool: &DbPool, from_local_user_id: LocalUserId, token: &str, ) -> Result { @@ -74,11 +68,8 @@ impl PasswordResetRequest { Self::create(pool, &form).await } - pub async fn read_from_token( - mut pool: &mut impl GetConn, - token: &str, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read_from_token(pool: &DbPool, token: &str) -> Result { + let conn = &mut get_conn(pool).await?; let mut hasher = Sha256::new(); hasher.update(token); let token_hash: String = bytes_to_hex(hasher.finalize().to_vec()); @@ -90,10 +81,10 @@ impl PasswordResetRequest { } pub async fn get_recent_password_resets_count( - mut pool: &mut impl GetConn, + pool: &DbPool, user_id: LocalUserId, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 7fdef962f..5c23f8071 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, naive_now, DbPool, GetConn}, + utils::{functions::lower, get_conn, naive_now, DbPool}, }; 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(mut pool: &mut impl GetConn, person_id: PersonId) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn read(pool: &DbPool, person_id: PersonId) -> Result { + let conn = &mut get_conn(pool).await?; person::table .filter(person::deleted.eq(false)) .find(person_id) .first::(conn) .await } - async fn delete(mut pool: &mut impl GetConn, person_id: PersonId) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn delete(pool: &DbPool, person_id: PersonId) -> Result { + let conn = &mut get_conn(pool).await?; diesel::delete(person::table.find(person_id)) .execute(conn) .await } - async fn create(mut pool: &mut impl GetConn, form: &PersonInsertForm) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn create(pool: &DbPool, form: &PersonInsertForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(person::table) .values(form) .get_result::(conn) .await } async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, person_id: PersonId, form: &PersonUpdateForm, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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(mut pool: &mut impl GetConn, form: &PersonInsertForm) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn upsert(pool: &DbPool, form: &PersonInsertForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(person::table) .values(form) .on_conflict(person::actor_id) @@ -67,11 +67,8 @@ impl Person { .get_result::(conn) .await } - pub async fn delete_account( - mut pool: &mut impl GetConn, - person_id: PersonId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn delete_account(pool: &DbPool, person_id: PersonId) -> Result { + let conn = &mut get_conn(pool).await?; // Set the local user info to none diesel::update(local_user::table.filter(local_user::person_id.eq(person_id))) @@ -107,11 +104,8 @@ pub fn is_banned(banned_: bool, expires: Option) -> bool #[async_trait] impl ApubActor for Person { - async fn read_from_apub_id( - mut pool: &mut impl GetConn, - object_id: &DbUrl, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result, Error> { + let conn = &mut get_conn(pool).await?; Ok( person::table .filter(person::deleted.eq(false)) @@ -124,11 +118,11 @@ impl ApubActor for Person { } async fn read_from_name( - mut pool: &mut impl GetConn, + pool: &DbPool, from_name: &str, include_deleted: bool, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; let mut q = person::table .into_boxed() .filter(person::local.eq(true)) @@ -140,11 +134,11 @@ impl ApubActor for Person { } async fn read_from_name_and_domain( - mut pool: &mut impl GetConn, + pool: &DbPool, person_name: &str, for_domain: &str, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; person::table .inner_join(instance::table) @@ -159,9 +153,9 @@ impl ApubActor for Person { #[async_trait] impl Followable for PersonFollower { type Form = PersonFollowerForm; - async fn follow(mut pool: &mut impl GetConn, form: &PersonFollowerForm) -> Result { + async fn follow(pool: &DbPool, form: &PersonFollowerForm) -> Result { use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(person_follower) .values(form) .on_conflict((follower_id, person_id)) @@ -170,19 +164,12 @@ impl Followable for PersonFollower { .get_result::(conn) .await } - async fn follow_accepted( - _: &mut impl GetConn, - _: CommunityId, - _: PersonId, - ) -> Result { + async fn follow_accepted(_: &DbPool, _: CommunityId, _: PersonId) -> Result { unimplemented!() } - async fn unfollow( - mut pool: &mut impl GetConn, - form: &PersonFollowerForm, - ) -> Result { + async fn unfollow(pool: &DbPool, form: &PersonFollowerForm) -> Result { use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::delete( person_follower .filter(follower_id.eq(&form.follower_id)) @@ -195,10 +182,10 @@ impl Followable for PersonFollower { impl PersonFollower { pub async fn list_followers( - mut pool: &mut impl GetConn, + pool: &DbPool, for_person_id: PersonId, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 538ee16a5..9cd275563 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; impl PersonBlock { pub async fn read( - mut pool: &mut impl GetConn, + pool: &DbPool, for_person_id: PersonId, for_recipient_id: PersonId, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; person_block .filter(person_id.eq(for_person_id)) .filter(target_id.eq(for_recipient_id)) @@ -26,11 +26,8 @@ impl PersonBlock { #[async_trait] impl Blockable for PersonBlock { type Form = PersonBlockForm; - async fn block( - mut pool: &mut impl GetConn, - person_block_form: &PersonBlockForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn block(pool: &DbPool, person_block_form: &PersonBlockForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(person_block) .values(person_block_form) .on_conflict((person_id, target_id)) @@ -39,11 +36,8 @@ impl Blockable for PersonBlock { .get_result::(conn) .await } - async fn unblock( - mut pool: &mut impl GetConn, - person_block_form: &Self::Form, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn unblock(pool: &DbPool, person_block_form: &Self::Form) -> Result { + let conn = &mut get_conn(pool).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 6f023f14b..559340e78 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; @@ -13,22 +13,16 @@ impl Crud for PersonMention { type InsertForm = PersonMentionInsertForm; type UpdateForm = PersonMentionUpdateForm; type IdType = PersonMentionId; - async fn read( - mut pool: &mut impl GetConn, - person_mention_id: PersonMentionId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn read(pool: &DbPool, person_mention_id: PersonMentionId) -> Result { + let conn = &mut get_conn(pool).await?; person_mention .find(person_mention_id) .first::(conn) .await } - async fn create( - mut pool: &mut impl GetConn, - person_mention_form: &Self::InsertForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn create(pool: &DbPool, person_mention_form: &Self::InsertForm) -> Result { + let conn = &mut get_conn(pool).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) @@ -41,11 +35,11 @@ impl Crud for PersonMention { } async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, person_mention_id: PersonMentionId, person_mention_form: &Self::UpdateForm, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(person_mention.find(person_mention_id)) .set(person_mention_form) .get_result::(conn) @@ -55,10 +49,10 @@ impl Crud for PersonMention { impl PersonMention { pub async fn mark_all_as_read( - mut pool: &mut impl GetConn, + pool: &DbPool, for_recipient_id: PersonId, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update( person_mention .filter(recipient_id.eq(for_recipient_id)) @@ -70,11 +64,11 @@ impl PersonMention { } pub async fn read_by_comment_and_person( - mut pool: &mut impl GetConn, + pool: &DbPool, for_comment_id: CommentId, for_recipient_id: PersonId, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 15982390f..6a4d53d3a 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::{naive_now, DbPool, GetConn, DELETED_REPLACEMENT_TEXT, FETCH_LIMIT_MAX}, + utils::{get_conn, naive_now, DbPool, 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(mut pool: &mut impl GetConn, post_id: PostId) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn read(pool: &DbPool, post_id: PostId) -> Result { + let conn = &mut get_conn(pool).await?; post.find(post_id).first::(conn).await } - async fn delete(mut pool: &mut impl GetConn, post_id: PostId) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn delete(pool: &DbPool, post_id: PostId) -> Result { + let conn = &mut get_conn(pool).await?; diesel::delete(post.find(post_id)).execute(conn).await } - async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(post) .values(form) .on_conflict(ap_id) @@ -60,11 +60,11 @@ impl Crud for Post { } async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, post_id: PostId, new_post: &Self::UpdateForm, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, the_community_id: CommunityId, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, the_community_id: CommunityId, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, for_creator_id: PersonId, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, for_creator_id: PersonId, for_community_id: Option, new_removed: bool, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; let mut update = diesel::update(post).into_boxed(); update = update.filter(creator_id.eq(for_creator_id)); @@ -148,11 +148,8 @@ impl Post { person_id == post_creator_id } - pub async fn read_from_apub_id( - mut pool: &mut impl GetConn, - object_id: Url, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn read_from_apub_id(pool: &DbPool, object_id: Url) -> Result, Error> { + let conn = &mut get_conn(pool).await?; let object_id: DbUrl = object_id.into(); Ok( post @@ -165,10 +162,10 @@ impl Post { } pub async fn fetch_pictrs_posts_for_creator( - mut pool: &mut impl GetConn, + pool: &DbPool, for_creator_id: PersonId, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; let pictrs_search = "%pictrs/image%"; post @@ -180,10 +177,10 @@ impl Post { /// Sets the url and thumbnails fields to None pub async fn remove_pictrs_post_images_and_thumbnails_for_creator( - mut pool: &mut impl GetConn, + pool: &DbPool, for_creator_id: PersonId, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; let pictrs_search = "%pictrs/image%"; diesel::update( @@ -200,10 +197,10 @@ impl Post { } pub async fn fetch_pictrs_posts_for_community( - mut pool: &mut impl GetConn, + pool: &DbPool, for_community_id: CommunityId, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; let pictrs_search = "%pictrs/image%"; post .filter(community_id.eq(for_community_id)) @@ -214,10 +211,10 @@ impl Post { /// Sets the url and thumbnails fields to None pub async fn remove_pictrs_post_images_and_thumbnails_for_community( - mut pool: &mut impl GetConn, + pool: &DbPool, for_community_id: CommunityId, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; let pictrs_search = "%pictrs/image%"; diesel::update( @@ -238,9 +235,9 @@ impl Post { impl Likeable for PostLike { type Form = PostLikeForm; type IdType = PostId; - async fn like(mut pool: &mut impl GetConn, post_like_form: &PostLikeForm) -> Result { + async fn like(pool: &DbPool, post_like_form: &PostLikeForm) -> Result { use crate::schema::post_like::dsl::{person_id, post_id, post_like}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(post_like) .values(post_like_form) .on_conflict((post_id, person_id)) @@ -249,13 +246,9 @@ impl Likeable for PostLike { .get_result::(conn) .await } - async fn remove( - mut pool: &mut impl GetConn, - person_id: PersonId, - post_id: PostId, - ) -> Result { + async fn remove(pool: &DbPool, person_id: PersonId, post_id: PostId) -> Result { use crate::schema::post_like::dsl; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::delete( dsl::post_like .filter(dsl::post_id.eq(post_id)) @@ -269,12 +262,9 @@ impl Likeable for PostLike { #[async_trait] impl Saveable for PostSaved { type Form = PostSavedForm; - async fn save( - mut pool: &mut impl GetConn, - post_saved_form: &PostSavedForm, - ) -> Result { + async fn save(pool: &DbPool, post_saved_form: &PostSavedForm) -> Result { use crate::schema::post_saved::dsl::{person_id, post_id, post_saved}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(post_saved) .values(post_saved_form) .on_conflict((post_id, person_id)) @@ -283,12 +273,9 @@ impl Saveable for PostSaved { .get_result::(conn) .await } - async fn unsave( - mut pool: &mut impl GetConn, - post_saved_form: &PostSavedForm, - ) -> Result { + async fn unsave(pool: &DbPool, post_saved_form: &PostSavedForm) -> Result { use crate::schema::post_saved::dsl::{person_id, post_id, post_saved}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::delete( post_saved .filter(post_id.eq(post_saved_form.post_id)) @@ -302,12 +289,9 @@ impl Saveable for PostSaved { #[async_trait] impl Readable for PostRead { type Form = PostReadForm; - async fn mark_as_read( - mut pool: &mut impl GetConn, - post_read_form: &PostReadForm, - ) -> Result { + async fn mark_as_read(pool: &DbPool, post_read_form: &PostReadForm) -> Result { use crate::schema::post_read::dsl::{person_id, post_id, post_read}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; insert_into(post_read) .values(post_read_form) .on_conflict((post_id, person_id)) @@ -317,12 +301,9 @@ impl Readable for PostRead { .await } - async fn mark_as_unread( - mut pool: &mut impl GetConn, - post_read_form: &PostReadForm, - ) -> Result { + async fn mark_as_unread(pool: &DbPool, post_read_form: &PostReadForm) -> Result { use crate::schema::post_read::dsl::{person_id, post_id, post_read}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 d089490f3..ece7d0901 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::{naive_now, DbPool, GetConn}, + utils::{get_conn, naive_now, DbPool}, }; use diesel::{ dsl::{insert_into, update}, @@ -18,11 +18,8 @@ impl Reportable for PostReport { type Form = PostReportForm; type IdType = PostReportId; - async fn report( - mut pool: &mut impl GetConn, - post_report_form: &PostReportForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn report(pool: &DbPool, post_report_form: &PostReportForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(post_report) .values(post_report_form) .get_result::(conn) @@ -30,11 +27,11 @@ impl Reportable for PostReport { } async fn resolve( - mut pool: &mut impl GetConn, + pool: &DbPool, report_id: Self::IdType, by_resolver_id: PersonId, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; update(post_report.find(report_id)) .set(( resolved.eq(true), @@ -46,11 +43,11 @@ impl Reportable for PostReport { } async fn unresolve( - mut pool: &mut impl GetConn, + pool: &DbPool, report_id: Self::IdType, by_resolver_id: PersonId, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 23d67c36b..cf6782270 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::RunQueryDsl; @@ -15,19 +15,16 @@ impl Crud for PrivateMessage { type InsertForm = PrivateMessageInsertForm; type UpdateForm = PrivateMessageUpdateForm; type IdType = PrivateMessageId; - async fn read( - mut pool: &mut impl GetConn, - private_message_id: PrivateMessageId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn read(pool: &DbPool, private_message_id: PrivateMessageId) -> Result { + let conn = &mut get_conn(pool).await?; private_message .find(private_message_id) .first::(conn) .await } - async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(private_message) .values(form) .on_conflict(ap_id) @@ -38,18 +35,18 @@ impl Crud for PrivateMessage { } async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, private_message_id: PrivateMessageId, form: &Self::UpdateForm, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(private_message.find(private_message_id)) .set(form) .get_result::(conn) .await } - async fn delete(mut pool: &mut impl GetConn, pm_id: Self::IdType) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn delete(pool: &DbPool, pm_id: Self::IdType) -> Result { + let conn = &mut get_conn(pool).await?; diesel::delete(private_message.find(pm_id)) .execute(conn) .await @@ -58,10 +55,10 @@ impl Crud for PrivateMessage { impl PrivateMessage { pub async fn mark_all_as_read( - mut pool: &mut impl GetConn, + pool: &DbPool, for_recipient_id: PersonId, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update( private_message .filter(recipient_id.eq(for_recipient_id)) @@ -73,10 +70,10 @@ impl PrivateMessage { } pub async fn read_from_apub_id( - mut pool: &mut impl GetConn, + pool: &DbPool, object_id: Url, ) -> Result, LemmyError> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 e7ed32109..5f2498c28 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::{naive_now, DbPool, GetConn}, + utils::{get_conn, naive_now, DbPool}, }; use diesel::{ dsl::{insert_into, update}, @@ -18,11 +18,8 @@ impl Reportable for PrivateMessageReport { type Form = PrivateMessageReportForm; type IdType = PrivateMessageReportId; - async fn report( - mut pool: &mut impl GetConn, - pm_report_form: &PrivateMessageReportForm, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn report(pool: &DbPool, pm_report_form: &PrivateMessageReportForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(private_message_report) .values(pm_report_form) .get_result::(conn) @@ -30,11 +27,11 @@ impl Reportable for PrivateMessageReport { } async fn resolve( - mut pool: &mut impl GetConn, + pool: &DbPool, report_id: Self::IdType, by_resolver_id: PersonId, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; update(private_message_report.find(report_id)) .set(( resolved.eq(true), @@ -46,11 +43,11 @@ impl Reportable for PrivateMessageReport { } async fn unresolve( - mut pool: &mut impl GetConn, + pool: &DbPool, report_id: Self::IdType, by_resolver_id: PersonId, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 aa50b4ef1..208b01d01 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; 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(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { + let conn = &mut get_conn(pool).await?; insert_into(registration_application) .values(form) .get_result::(conn) .await } - async fn read(mut pool: &mut impl GetConn, id_: Self::IdType) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn read(pool: &DbPool, id_: Self::IdType) -> Result { + let conn = &mut get_conn(pool).await?; registration_application.find(id_).first::(conn).await } async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, id_: Self::IdType, form: &Self::UpdateForm, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(registration_application.find(id_)) .set(form) .get_result::(conn) .await } - async fn delete(mut pool: &mut impl GetConn, id_: Self::IdType) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn delete(pool: &DbPool, id_: Self::IdType) -> Result { + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, local_user_id_: LocalUserId, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 75d62b92d..4e0d9c1bd 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; 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(mut pool: &mut impl GetConn) -> Result { + pub async fn init(pool: &DbPool) -> Result { Self::read_secrets(pool).await } - async fn read_secrets(mut pool: &mut impl GetConn) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn read_secrets(pool: &DbPool) -> Result { + let conn = &mut get_conn(pool).await?; secret.first::(conn).await } } diff --git a/crates/db_schema/src/impls/site.rs b/crates/db_schema/src/impls/site.rs index 101a2e872..3363edc93 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; 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: &mut impl GetConn, _site_id: SiteId) -> Result { + async fn read(_pool: &DbPool, _site_id: SiteId) -> Result { unimplemented!() } - async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result { + let conn = &mut get_conn(pool).await?; let is_new_site = match &form.actor_id { Some(id_) => Site::read_from_apub_id(pool, id_).await?.is_none(), None => true, @@ -48,29 +48,26 @@ impl Crud for Site { } async fn update( - mut pool: &mut impl GetConn, + pool: &DbPool, site_id: SiteId, new_site: &Self::UpdateForm, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; diesel::update(site.find(site_id)) .set(new_site) .get_result::(conn) .await } - async fn delete(mut pool: &mut impl GetConn, site_id: SiteId) -> Result { - let conn = &mut *pool.get_conn().await?; + async fn delete(pool: &DbPool, site_id: SiteId) -> Result { + let conn = &mut get_conn(pool).await?; diesel::delete(site.find(site_id)).execute(conn).await } } impl Site { - pub async fn read_from_apub_id( - mut pool: &mut impl GetConn, - object_id: &DbUrl, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result, Error> { + let conn = &mut get_conn(pool).await?; Ok( site .filter(actor_id.eq(object_id)) @@ -82,8 +79,8 @@ impl Site { } // TODO this needs fixed - pub async fn read_remote_sites(mut pool: &mut impl GetConn) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn read_remote_sites(pool: &DbPool) -> Result, Error> { + let conn = &mut get_conn(pool).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 e74c54a16..ec985a3c8 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl}; use diesel_async::{AsyncPgConnection, RunQueryDsl}; impl Tagline { pub async fn replace( - mut pool: &mut impl GetConn, + pool: &DbPool, for_local_site_id: LocalSiteId, list_content: Option>, ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; if let Some(list) = list_content { conn .build_transaction() @@ -54,11 +54,8 @@ impl Tagline { .get_results::(conn) .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?; + pub async fn get_all(pool: &DbPool, for_local_site_id: LocalSiteId) -> Result, Error> { + let conn = &mut get_conn(pool).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 60d5e1209..12b92b3d9 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, GetConn}, + utils::DbPool, }; use diesel::result::Error; @@ -9,21 +9,17 @@ pub trait Crud { type InsertForm; type UpdateForm; type IdType; - async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result + async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result where Self: Sized; - async fn read(mut pool: &mut impl GetConn, id: Self::IdType) -> Result + async fn read(pool: &DbPool, 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( - mut pool: &mut impl GetConn, - id: Self::IdType, - form: &Self::UpdateForm, - ) -> Result + async fn update(pool: &DbPool, id: Self::IdType, form: &Self::UpdateForm) -> Result where Self: Sized; - async fn delete(_pool: &mut impl GetConn, _id: Self::IdType) -> Result + async fn delete(_pool: &DbPool, _id: Self::IdType) -> Result where Self: Sized, Self::IdType: Send, @@ -35,17 +31,17 @@ pub trait Crud { #[async_trait] pub trait Followable { type Form; - async fn follow(mut pool: &mut impl GetConn, form: &Self::Form) -> Result + async fn follow(pool: &DbPool, form: &Self::Form) -> Result where Self: Sized; async fn follow_accepted( - mut pool: &mut impl GetConn, + pool: &DbPool, community_id: CommunityId, person_id: PersonId, ) -> Result where Self: Sized; - async fn unfollow(mut pool: &mut impl GetConn, form: &Self::Form) -> Result + async fn unfollow(pool: &DbPool, form: &Self::Form) -> Result where Self: Sized; } @@ -53,10 +49,10 @@ pub trait Followable { #[async_trait] pub trait Joinable { type Form; - async fn join(mut pool: &mut impl GetConn, form: &Self::Form) -> Result + async fn join(pool: &DbPool, form: &Self::Form) -> Result where Self: Sized; - async fn leave(mut pool: &mut impl GetConn, form: &Self::Form) -> Result + async fn leave(pool: &DbPool, form: &Self::Form) -> Result where Self: Sized; } @@ -65,11 +61,11 @@ pub trait Joinable { pub trait Likeable { type Form; type IdType; - async fn like(mut pool: &mut impl GetConn, form: &Self::Form) -> Result + async fn like(pool: &DbPool, form: &Self::Form) -> Result where Self: Sized; async fn remove( - mut pool: &mut impl GetConn, + pool: &DbPool, person_id: PersonId, item_id: Self::IdType, ) -> Result @@ -80,10 +76,10 @@ pub trait Likeable { #[async_trait] pub trait Bannable { type Form; - async fn ban(mut pool: &mut impl GetConn, form: &Self::Form) -> Result + async fn ban(pool: &DbPool, form: &Self::Form) -> Result where Self: Sized; - async fn unban(mut pool: &mut impl GetConn, form: &Self::Form) -> Result + async fn unban(pool: &DbPool, form: &Self::Form) -> Result where Self: Sized; } @@ -91,10 +87,10 @@ pub trait Bannable { #[async_trait] pub trait Saveable { type Form; - async fn save(mut pool: &mut impl GetConn, form: &Self::Form) -> Result + async fn save(pool: &DbPool, form: &Self::Form) -> Result where Self: Sized; - async fn unsave(mut pool: &mut impl GetConn, form: &Self::Form) -> Result + async fn unsave(pool: &DbPool, form: &Self::Form) -> Result where Self: Sized; } @@ -102,10 +98,10 @@ pub trait Saveable { #[async_trait] pub trait Blockable { type Form; - async fn block(mut pool: &mut impl GetConn, form: &Self::Form) -> Result + async fn block(pool: &DbPool, form: &Self::Form) -> Result where Self: Sized; - async fn unblock(mut pool: &mut impl GetConn, form: &Self::Form) -> Result + async fn unblock(pool: &DbPool, form: &Self::Form) -> Result where Self: Sized; } @@ -113,10 +109,10 @@ pub trait Blockable { #[async_trait] pub trait Readable { type Form; - async fn mark_as_read(mut pool: &mut impl GetConn, form: &Self::Form) -> Result + async fn mark_as_read(pool: &DbPool, form: &Self::Form) -> Result where Self: Sized; - async fn mark_as_unread(mut pool: &mut impl GetConn, form: &Self::Form) -> Result + async fn mark_as_unread(pool: &DbPool, form: &Self::Form) -> Result where Self: Sized; } @@ -125,18 +121,18 @@ pub trait Readable { pub trait Reportable { type Form; type IdType; - async fn report(mut pool: &mut impl GetConn, form: &Self::Form) -> Result + async fn report(pool: &DbPool, form: &Self::Form) -> Result where Self: Sized; async fn resolve( - mut pool: &mut impl GetConn, + pool: &DbPool, report_id: Self::IdType, resolver_id: PersonId, ) -> Result where Self: Sized; async fn unresolve( - mut pool: &mut impl GetConn, + pool: &DbPool, report_id: Self::IdType, resolver_id: PersonId, ) -> Result @@ -153,23 +149,20 @@ pub trait JoinView { #[async_trait] pub trait ApubActor { - async fn read_from_apub_id( - mut pool: &mut impl GetConn, - object_id: &DbUrl, - ) -> Result, Error> + async fn read_from_apub_id(pool: &DbPool, 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( - mut pool: &mut impl GetConn, + pool: &DbPool, actor_name: &str, include_deleted: bool, ) -> Result where Self: Sized; async fn read_from_name_and_domain( - mut pool: &mut impl GetConn, + pool: &DbPool, actor_name: &str, protocol_domain: &str, ) -> Result diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 3db39d738..e4f5d6cae 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -50,48 +50,33 @@ const POOL_TIMEOUT: Option = Some(Duration::from_secs(5)); pub type DbPool = Pool; #[async_trait] -pub trait GetConn: Send { - type Conn<'conn>: std::ops::DerefMut + Send - where - Self: 'conn; +pub trait GetConn { + type Conn: std::ops::Deref; - // 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 fn get_conn(self) -> Result; } #[async_trait] impl<'a> GetConn for &'a DbPool { - type Conn<'conn> = PooledConnection; + type Conn = PooledConnection; - async fn get_conn<'conn>(&mut self) -> Result, DieselError> - where - 'life0: 'conn, //where - //Self::Conn: 'life0, - { + async fn get_conn(self) -> Result { self.get().await.map_err(|e| QueryBuilderError(e.into())) } } #[async_trait] -impl GetConn for AsyncPgConnection { - type Conn<'conn> = &'conn mut AsyncPgConnection; +impl<'a> GetConn for &'a mut AsyncPgConnection { + type Conn = Self; - async fn get_conn<'conn>(&mut self) -> Result, DieselError> - where - 'life0: 'conn, //where - //Self::Conn: 'life0, - { + async fn get_conn(self) -> Result { 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 d2a1ea45c..4a5397b32 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::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; use typed_builder::TypedBuilder; @@ -40,11 +40,11 @@ impl CommentReportView { /// /// * `report_id` - the report id to obtain pub async fn read( - mut pool: &mut impl GetConn, + pool: &DbPool, report_id: CommentReportId, my_person_id: PersonId, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, my_person_id: PersonId, admin: bool, community_id: Option, ) -> Result { use diesel::dsl::count; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 a64771769..f3b1f83a8 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, limit_and_offset, DbPool, GetConn}, + utils::{fuzzy_search, get_conn, limit_and_offset, DbPool}, CommentSortType, ListingType, }; @@ -57,11 +57,11 @@ type CommentViewTuple = ( impl CommentView { pub async fn read( - mut pool: &mut impl GetConn, + pool: &DbPool, comment_id: CommentId, my_person_id: Option, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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(mut pool: &mut impl GetConn) -> Data { + async fn init_data(pool: &DbPool) -> 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, mut pool: &mut impl GetConn) { + async fn cleanup(data: Data, pool: &DbPool) { 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, mut pool: &mut impl GetConn) -> CommentView { + async fn expected_comment_view(data: &Data, pool: &DbPool) -> 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 bcde2d718..66d583e32 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; use std::collections::HashMap; type CustomEmojiTuple = (CustomEmoji, Option); impl CustomEmojiView { - pub async fn get(mut pool: &mut impl GetConn, emoji_id: CustomEmojiId) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn get(pool: &DbPool, emoji_id: CustomEmojiId) -> Result { + let conn = &mut get_conn(pool).await?; let emojis = custom_emoji::table .find(emoji_id) .left_join( @@ -35,11 +35,8 @@ impl CustomEmojiView { } } - pub async fn get_all( - mut pool: &mut impl GetConn, - for_local_site_id: LocalSiteId, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn get_all(pool: &DbPool, for_local_site_id: LocalSiteId) -> Result, Error> { + let conn = &mut get_conn(pool).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 591dea7d2..f37986cc9 100644 --- a/crates/db_views/src/local_user_view.rs +++ b/crates/db_views/src/local_user_view.rs @@ -7,17 +7,14 @@ use lemmy_db_schema::{ schema::{local_user, person, person_aggregates}, source::{local_user::LocalUser, person::Person}, traits::JoinView, - utils::{functions::lower, DbPool, GetConn}, + utils::{functions::lower, get_conn, DbPool}, }; type LocalUserViewTuple = (LocalUser, Person, PersonAggregates); impl LocalUserView { - pub async fn read( - mut pool: &mut impl GetConn, - local_user_id: LocalUserId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read(pool: &DbPool, local_user_id: LocalUserId) -> Result { + let conn = &mut get_conn(pool).await?; let (local_user, person, counts) = local_user::table .find(local_user_id) @@ -37,11 +34,8 @@ impl LocalUserView { }) } - pub async fn read_person( - mut pool: &mut impl GetConn, - person_id: PersonId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read_person(pool: &DbPool, person_id: PersonId) -> Result { + let conn = &mut get_conn(pool).await?; let (local_user, person, counts) = local_user::table .filter(person::id.eq(person_id)) .inner_join(person::table) @@ -60,8 +54,8 @@ impl LocalUserView { }) } - pub async fn read_from_name(mut pool: &mut impl GetConn, name: &str) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read_from_name(pool: &DbPool, name: &str) -> Result { + let conn = &mut get_conn(pool).await?; let (local_user, person, counts) = local_user::table .filter(lower(person::name).eq(name.to_lowercase())) .inner_join(person::table) @@ -80,11 +74,8 @@ impl LocalUserView { }) } - 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?; + pub async fn find_by_email_or_name(pool: &DbPool, name_or_email: &str) -> Result { + let conn = &mut get_conn(pool).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))) @@ -107,8 +98,8 @@ impl LocalUserView { }) } - pub async fn find_by_email(mut pool: &mut impl GetConn, from_email: &str) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn find_by_email(pool: &DbPool, from_email: &str) -> Result { + let conn = &mut get_conn(pool).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))) @@ -127,8 +118,8 @@ impl LocalUserView { }) } - pub async fn list_admins_with_emails(mut pool: &mut impl GetConn) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list_admins_with_emails(pool: &DbPool) -> Result, Error> { + let conn = &mut get_conn(pool).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 5627b4ba1..19822c795 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::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; use typed_builder::TypedBuilder; @@ -49,11 +49,11 @@ impl PostReportView { /// /// * `report_id` - the report id to obtain pub async fn read( - mut pool: &mut impl GetConn, + pool: &DbPool, report_id: PostReportId, my_person_id: PersonId, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, my_person_id: PersonId, admin: bool, community_id: Option, ) -> Result { use diesel::dsl::count; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 2a42b9e2f..d1e974d8a 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, limit_and_offset, DbPool, GetConn}, + utils::{fuzzy_search, get_conn, limit_and_offset, DbPool}, ListingType, SortType, }; @@ -65,12 +65,12 @@ sql_function!(fn coalesce(x: sql_types::Nullable, y: sql_type impl PostView { pub async fn read( - mut pool: &mut impl GetConn, + pool: &DbPool, post_id: PostId, my_person_id: Option, is_mod_or_admin: Option, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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(mut pool: &mut impl GetConn) -> Data { + async fn init_data(pool: &DbPool) -> 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, mut pool: &mut impl GetConn) { + async fn cleanup(data: Data, pool: &DbPool) { 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, mut pool: &mut impl GetConn) -> PostView { + async fn expected_post_view(data: &Data, pool: &DbPool) -> 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 af404517b..2bcad6f83 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::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; use typed_builder::TypedBuilder; @@ -26,11 +26,8 @@ impl PrivateMessageReportView { /// returns the PrivateMessageReportView for the provided report_id /// /// * `report_id` - the report id to obtain - pub async fn read( - mut pool: &mut impl GetConn, - report_id: PrivateMessageReportId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read(pool: &DbPool, report_id: PrivateMessageReportId) -> Result { + let conn = &mut get_conn(pool).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) = @@ -67,9 +64,9 @@ impl PrivateMessageReportView { } /// Returns the current unresolved post report count for the communities you mod - pub async fn get_report_count(mut pool: &mut impl GetConn) -> Result { + pub async fn get_report_count(pool: &DbPool) -> Result { use diesel::dsl::count; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 a044629fb..76b817a96 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::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; use tracing::debug; use typed_builder::TypedBuilder; @@ -22,11 +22,8 @@ use typed_builder::TypedBuilder; type PrivateMessageViewTuple = (PrivateMessage, Person, Person); impl PrivateMessageView { - pub async fn read( - mut pool: &mut impl GetConn, - private_message_id: PrivateMessageId, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read(pool: &DbPool, private_message_id: PrivateMessageId) -> Result { + let conn = &mut get_conn(pool).await?; let person_alias_1 = diesel::alias!(person as person1); let (private_message, creator, recipient) = private_message::table @@ -52,12 +49,9 @@ impl PrivateMessageView { } /// Gets the number of unread messages - pub async fn get_unread_messages( - mut pool: &mut impl GetConn, - my_person_id: PersonId, - ) -> Result { + pub async fn get_unread_messages(pool: &DbPool, my_person_id: PersonId) -> Result { use diesel::dsl::count; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 de7b4fa08..9963ed466 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::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; use typed_builder::TypedBuilder; @@ -24,11 +24,8 @@ type RegistrationApplicationViewTuple = (RegistrationApplication, LocalUser, Person, Option); impl RegistrationApplicationView { - pub async fn read( - mut pool: &mut impl GetConn, - registration_application_id: i32, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read(pool: &DbPool, registration_application_id: i32) -> Result { + let conn = &mut get_conn(pool).await?; let person_alias_1 = diesel::alias!(person as person1); let (registration_application, creator_local_user, creator, admin) = @@ -61,11 +58,8 @@ impl RegistrationApplicationView { } /// Returns the current unread registration_application count - pub async fn get_unread_count( - mut pool: &mut impl GetConn, - verified_email_only: bool, - ) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn get_unread_count(pool: &DbPool, verified_email_only: bool) -> Result { + let conn = &mut get_conn(pool).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 e8e06e4fe..a1d0231a2 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; impl SiteView { - pub async fn read_local(mut pool: &mut impl GetConn) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read_local(pool: &DbPool) -> Result { + let conn = &mut get_conn(pool).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 a0589cc7c..42c3a53e0 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::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, CommentSortType, }; use typed_builder::TypedBuilder; @@ -55,11 +55,11 @@ type CommentReplyViewTuple = ( impl CommentReplyView { pub async fn read( - mut pool: &mut impl GetConn, + pool: &DbPool, comment_reply_id: CommentReplyId, my_person_id: Option, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; let person_alias_1 = diesel::alias!(person as person1); // The left join below will return None in this case @@ -155,13 +155,10 @@ impl CommentReplyView { } /// Gets the number of unread replies - pub async fn get_unread_replies( - mut pool: &mut impl GetConn, - my_person_id: PersonId, - ) -> Result { + pub async fn get_unread_replies(pool: &DbPool, my_person_id: PersonId) -> Result { use diesel::dsl::count; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 836426c67..d87bea37f 100644 --- a/crates/db_views_actor/src/community_block_view.rs +++ b/crates/db_views_actor/src/community_block_view.rs @@ -6,17 +6,14 @@ use lemmy_db_schema::{ schema::{community, community_block, person}, source::{community::Community, person::Person}, traits::JoinView, - utils::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; type CommunityBlockViewTuple = (Person, Community); impl CommunityBlockView { - pub async fn for_person( - mut pool: &mut impl GetConn, - person_id: PersonId, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result, Error> { + let conn = &mut get_conn(pool).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 b056b174b..ccc7ae706 100644 --- a/crates/db_views_actor/src/community_follower_view.rs +++ b/crates/db_views_actor/src/community_follower_view.rs @@ -6,17 +6,14 @@ use lemmy_db_schema::{ schema::{community, community_follower, person}, source::{community::Community, person::Person}, traits::JoinView, - utils::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; type CommunityFollowerViewTuple = (Community, Person); impl CommunityFollowerView { - pub async fn for_community( - mut pool: &mut impl GetConn, - community_id: CommunityId, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn for_community(pool: &DbPool, community_id: CommunityId) -> Result, Error> { + let conn = &mut get_conn(pool).await?; let res = community_follower::table .inner_join(community::table) .inner_join(person::table) @@ -29,11 +26,8 @@ impl CommunityFollowerView { Ok(res.into_iter().map(Self::from_tuple).collect()) } - pub async fn for_person( - mut pool: &mut impl GetConn, - person_id: PersonId, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result, Error> { + let conn = &mut get_conn(pool).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 3007ca885..afdfbfb28 100644 --- a/crates/db_views_actor/src/community_moderator_view.rs +++ b/crates/db_views_actor/src/community_moderator_view.rs @@ -6,17 +6,14 @@ use lemmy_db_schema::{ schema::{community, community_moderator, person}, source::{community::Community, person::Person}, traits::JoinView, - utils::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; type CommunityModeratorViewTuple = (Community, Person); impl CommunityModeratorView { - pub async fn for_community( - mut pool: &mut impl GetConn, - community_id: CommunityId, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn for_community(pool: &DbPool, community_id: CommunityId) -> Result, Error> { + let conn = &mut get_conn(pool).await?; let res = community_moderator::table .inner_join(community::table) .inner_join(person::table) @@ -28,11 +25,8 @@ impl CommunityModeratorView { Ok(res.into_iter().map(Self::from_tuple).collect()) } - pub async fn for_person( - mut pool: &mut impl GetConn, - person_id: PersonId, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result, Error> { + let conn = &mut get_conn(pool).await?; let res = community_moderator::table .inner_join(community::table) .inner_join(person::table) @@ -48,8 +42,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(mut pool: &mut impl GetConn) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn get_community_first_mods(pool: &DbPool) -> Result, Error> { + let conn = &mut get_conn(pool).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 89ccce104..35eacf0f7 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::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; impl CommunityPersonBanView { pub async fn get( - mut pool: &mut impl GetConn, + pool: &DbPool, from_person_id: PersonId, from_community_id: CommunityId, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 403f6b9b8..94bcdaf92 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, limit_and_offset, DbPool, GetConn}, + utils::{fuzzy_search, get_conn, limit_and_offset, DbPool}, ListingType, SortType, }; @@ -34,12 +34,12 @@ type CommunityViewTuple = ( impl CommunityView { pub async fn read( - mut pool: &mut impl GetConn, + pool: &DbPool, community_id: CommunityId, my_person_id: Option, is_mod_or_admin: Option, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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( - mut pool: &mut impl GetConn, + pool: &DbPool, 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 1443c6538..6e10ee7b6 100644 --- a/crates/db_views_actor/src/person_block_view.rs +++ b/crates/db_views_actor/src/person_block_view.rs @@ -6,17 +6,14 @@ use lemmy_db_schema::{ schema::{person, person_block}, source::person::Person, traits::JoinView, - utils::{DbPool, GetConn}, + utils::{get_conn, DbPool}, }; type PersonBlockViewTuple = (Person, Person); impl PersonBlockView { - pub async fn for_person( - mut pool: &mut impl GetConn, - person_id: PersonId, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result, Error> { + let conn = &mut get_conn(pool).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 183ad3886..803abdb39 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::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, CommentSortType, }; use typed_builder::TypedBuilder; @@ -56,11 +56,11 @@ type PersonMentionViewTuple = ( impl PersonMentionView { pub async fn read( - mut pool: &mut impl GetConn, + pool: &DbPool, person_mention_id: PersonMentionId, my_person_id: Option, ) -> Result { - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; let person_alias_1 = diesel::alias!(person as person1); // The left join below will return None in this case @@ -156,12 +156,9 @@ impl PersonMentionView { } /// Gets the number of unread mentions - pub async fn get_unread_mentions( - mut pool: &mut impl GetConn, - my_person_id: PersonId, - ) -> Result { + pub async fn get_unread_mentions(pool: &DbPool, my_person_id: PersonId) -> Result { use diesel::dsl::count; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).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 1918334b7..2a7a2ce79 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, limit_and_offset, DbPool, GetConn}, + utils::{fuzzy_search, get_conn, limit_and_offset, DbPool}, SortType, }; use std::iter::Iterator; @@ -23,8 +23,8 @@ use typed_builder::TypedBuilder; type PersonViewTuple = (Person, PersonAggregates); impl PersonView { - pub async fn read(mut pool: &mut impl GetConn, person_id: PersonId) -> Result { - let conn = &mut *pool.get_conn().await?; + pub async fn read(pool: &DbPool, person_id: PersonId) -> Result { + let conn = &mut get_conn(pool).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(mut pool: &mut impl GetConn) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn admins(pool: &DbPool) -> Result, Error> { + let conn = &mut get_conn(pool).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(mut pool: &mut impl GetConn) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn banned(pool: &DbPool) -> Result, Error> { + let conn = &mut get_conn(pool).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 09fbc292c..12e47fbbc 100644 --- a/crates/db_views_moderator/src/admin_purge_comment_view.rs +++ b/crates/db_views_moderator/src/admin_purge_comment_view.rs @@ -14,17 +14,14 @@ use lemmy_db_schema::{ schema::{admin_purge_comment, person, post}, source::{moderator::AdminPurgeComment, person::Person, post::Post}, traits::JoinView, - utils::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; type AdminPurgeCommentViewTuple = (AdminPurgeComment, Option, Post); impl AdminPurgeCommentView { - pub async fn list( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 86cec46d1..e3a7a7897 100644 --- a/crates/db_views_moderator/src/admin_purge_community_view.rs +++ b/crates/db_views_moderator/src/admin_purge_community_view.rs @@ -14,17 +14,14 @@ use lemmy_db_schema::{ schema::{admin_purge_community, person}, source::{moderator::AdminPurgeCommunity, person::Person}, traits::JoinView, - utils::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, Option); impl AdminPurgeCommunityView { - pub async fn list( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 5a18a5cde..fff5b2d51 100644 --- a/crates/db_views_moderator/src/admin_purge_person_view.rs +++ b/crates/db_views_moderator/src/admin_purge_person_view.rs @@ -14,17 +14,14 @@ use lemmy_db_schema::{ schema::{admin_purge_person, person}, source::{moderator::AdminPurgePerson, person::Person}, traits::JoinView, - utils::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; type AdminPurgePersonViewTuple = (AdminPurgePerson, Option); impl AdminPurgePersonView { - pub async fn list( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 53ca2a4ef..e37e66b1b 100644 --- a/crates/db_views_moderator/src/admin_purge_post_view.rs +++ b/crates/db_views_moderator/src/admin_purge_post_view.rs @@ -14,17 +14,14 @@ use lemmy_db_schema::{ schema::{admin_purge_post, community, person}, source::{community::Community, moderator::AdminPurgePost, person::Person}, traits::JoinView, - utils::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; type AdminPurgePostViewTuple = (AdminPurgePost, Option, Community); impl AdminPurgePostView { - pub async fn list( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 c36ccd996..6df6376f5 100644 --- a/crates/db_views_moderator/src/mod_add_community_view.rs +++ b/crates/db_views_moderator/src/mod_add_community_view.rs @@ -14,17 +14,14 @@ use lemmy_db_schema::{ schema::{community, mod_add_community, person}, source::{community::Community, moderator::ModAddCommunity, person::Person}, traits::JoinView, - utils::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; type ModAddCommunityViewTuple = (ModAddCommunity, Option, Community, Person); impl ModAddCommunityView { - pub async fn list( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 13e090559..ef408ce3a 100644 --- a/crates/db_views_moderator/src/mod_add_view.rs +++ b/crates/db_views_moderator/src/mod_add_view.rs @@ -14,17 +14,14 @@ use lemmy_db_schema::{ schema::{mod_add, person}, source::{moderator::ModAdd, person::Person}, traits::JoinView, - utils::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; type ModAddViewTuple = (ModAdd, Option, Person); impl ModAddView { - pub async fn list( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 5db3cd207..c7fb73956 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,17 +14,14 @@ use lemmy_db_schema::{ schema::{community, mod_ban_from_community, person}, source::{community::Community, moderator::ModBanFromCommunity, person::Person}, traits::JoinView, - utils::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; type ModBanFromCommunityViewTuple = (ModBanFromCommunity, Option, Community, Person); impl ModBanFromCommunityView { - pub async fn list( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 1ab173695..7bdf0dcf7 100644 --- a/crates/db_views_moderator/src/mod_ban_view.rs +++ b/crates/db_views_moderator/src/mod_ban_view.rs @@ -14,17 +14,14 @@ use lemmy_db_schema::{ schema::{mod_ban, person}, source::{moderator::ModBan, person::Person}, traits::JoinView, - utils::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; type ModBanViewTuple = (ModBan, Option, Person); impl ModBanView { - pub async fn list( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 b47ad9149..66bd4264f 100644 --- a/crates/db_views_moderator/src/mod_feature_post_view.rs +++ b/crates/db_views_moderator/src/mod_feature_post_view.rs @@ -14,17 +14,14 @@ use lemmy_db_schema::{ schema::{community, mod_feature_post, person, post}, source::{community::Community, moderator::ModFeaturePost, person::Person, post::Post}, traits::JoinView, - utils::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; type ModFeaturePostViewTuple = (ModFeaturePost, Option, Post, Community); impl ModFeaturePostView { - pub async fn list( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 638089117..c2c6294bf 100644 --- a/crates/db_views_moderator/src/mod_hide_community_view.rs +++ b/crates/db_views_moderator/src/mod_hide_community_view.rs @@ -14,18 +14,15 @@ use lemmy_db_schema::{ schema::{community, mod_hide_community, person}, source::{community::Community, moderator::ModHideCommunity, person::Person}, traits::JoinView, - utils::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; 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( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 4865f886a..15ff7855c 100644 --- a/crates/db_views_moderator/src/mod_lock_post_view.rs +++ b/crates/db_views_moderator/src/mod_lock_post_view.rs @@ -14,17 +14,14 @@ use lemmy_db_schema::{ schema::{community, mod_lock_post, person, post}, source::{community::Community, moderator::ModLockPost, person::Person, post::Post}, traits::JoinView, - utils::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; type ModLockPostViewTuple = (ModLockPost, Option, Post, Community); impl ModLockPostView { - pub async fn list( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 c296d4add..0d33974b8 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::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; type ModRemoveCommentViewTuple = ( @@ -33,11 +33,8 @@ type ModRemoveCommentViewTuple = ( ); impl ModRemoveCommentView { - pub async fn list( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 2c84628a5..50f99e528 100644 --- a/crates/db_views_moderator/src/mod_remove_community_view.rs +++ b/crates/db_views_moderator/src/mod_remove_community_view.rs @@ -14,17 +14,14 @@ use lemmy_db_schema::{ schema::{community, mod_remove_community, person}, source::{community::Community, moderator::ModRemoveCommunity, person::Person}, traits::JoinView, - utils::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; type ModRemoveCommunityTuple = (ModRemoveCommunity, Option, Community); impl ModRemoveCommunityView { - pub async fn list( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 19a3e5a88..fff5df466 100644 --- a/crates/db_views_moderator/src/mod_remove_post_view.rs +++ b/crates/db_views_moderator/src/mod_remove_post_view.rs @@ -14,17 +14,14 @@ use lemmy_db_schema::{ schema::{community, mod_remove_post, person, post}, source::{community::Community, moderator::ModRemovePost, person::Person, post::Post}, traits::JoinView, - utils::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; type ModRemovePostViewTuple = (ModRemovePost, Option, Post, Community); impl ModRemovePostView { - pub async fn list( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 6a3da279e..60da8e83f 100644 --- a/crates/db_views_moderator/src/mod_transfer_community_view.rs +++ b/crates/db_views_moderator/src/mod_transfer_community_view.rs @@ -14,17 +14,14 @@ use lemmy_db_schema::{ schema::{community, mod_transfer_community, person}, source::{community::Community, moderator::ModTransferCommunity, person::Person}, traits::JoinView, - utils::{limit_and_offset, DbPool, GetConn}, + utils::{get_conn, limit_and_offset, DbPool}, }; type ModTransferCommunityViewTuple = (ModTransferCommunity, Option, Community, Person); impl ModTransferCommunityView { - pub async fn list( - mut pool: &mut impl GetConn, - params: ModlogListParams, - ) -> Result, Error> { - let conn = &mut *pool.get_conn().await?; + pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result, Error> { + let conn = &mut get_conn(pool).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 caa33178d..2d894c683 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, GetConn}, + utils::DbPool, CommentSortType, ListingType, SortType, @@ -227,7 +227,7 @@ async fn get_feed( #[tracing::instrument(skip_all)] async fn get_feed_user( - mut pool: &mut impl GetConn, + pool: &DbPool, 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( - mut pool: &mut impl GetConn, + pool: &DbPool, 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( - mut pool: &mut impl GetConn, + pool: &DbPool, 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( - mut pool: &mut impl GetConn, + pool: &DbPool, jwt_secret: &str, jwt: &str, protocol_and_hostname: &str, diff --git a/src/code_migrations.rs b/src/code_migrations.rs index 33100d277..c69ce591c 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -33,16 +33,13 @@ use lemmy_db_schema::{ site::{Site, SiteInsertForm, SiteUpdateForm}, }, traits::Crud, - utils::{naive_now, DbPool, GetConn}, + utils::{get_conn, naive_now, DbPool}, }; use lemmy_utils::{error::LemmyError, settings::structs::Settings}; use tracing::info; use url::Url; -pub async fn run_advanced_migrations( - mut pool: &mut impl GetConn, - settings: &Settings, -) -> Result<(), LemmyError> { +pub async fn run_advanced_migrations(pool: &DbPool, 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?; @@ -59,11 +56,11 @@ pub async fn run_advanced_migrations( } async fn user_updates_2020_04_02( - mut pool: &mut impl GetConn, + pool: &DbPool, protocol_and_hostname: &str, ) -> Result<(), LemmyError> { use lemmy_db_schema::schema::person::dsl::{actor_id, local, person}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; info!("Running user_updates_2020_04_02"); @@ -97,11 +94,11 @@ async fn user_updates_2020_04_02( } async fn community_updates_2020_04_02( - mut pool: &mut impl GetConn, + pool: &DbPool, protocol_and_hostname: &str, ) -> Result<(), LemmyError> { use lemmy_db_schema::schema::community::dsl::{actor_id, community, local}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; info!("Running community_updates_2020_04_02"); @@ -136,11 +133,11 @@ async fn community_updates_2020_04_02( } async fn post_updates_2020_04_03( - mut pool: &mut impl GetConn, + pool: &DbPool, protocol_and_hostname: &str, ) -> Result<(), LemmyError> { use lemmy_db_schema::schema::post::dsl::{ap_id, local, post}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; info!("Running post_updates_2020_04_03"); @@ -171,11 +168,11 @@ async fn post_updates_2020_04_03( } async fn comment_updates_2020_04_03( - mut pool: &mut impl GetConn, + pool: &DbPool, protocol_and_hostname: &str, ) -> Result<(), LemmyError> { use lemmy_db_schema::schema::comment::dsl::{ap_id, comment, local}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; info!("Running comment_updates_2020_04_03"); @@ -206,11 +203,11 @@ async fn comment_updates_2020_04_03( } async fn private_message_updates_2020_05_05( - mut pool: &mut impl GetConn, + pool: &DbPool, protocol_and_hostname: &str, ) -> Result<(), LemmyError> { use lemmy_db_schema::schema::private_message::dsl::{ap_id, local, private_message}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; info!("Running private_message_updates_2020_05_05"); @@ -243,11 +240,11 @@ async fn private_message_updates_2020_05_05( } async fn post_thumbnail_url_updates_2020_07_27( - mut pool: &mut impl GetConn, + pool: &DbPool, protocol_and_hostname: &str, ) -> Result<(), LemmyError> { use lemmy_db_schema::schema::post::dsl::{post, thumbnail_url}; - let conn = &mut *pool.get_conn().await?; + let conn = &mut get_conn(pool).await?; info!("Running post_thumbnail_url_updates_2020_07_27"); @@ -274,8 +271,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(mut pool: &mut impl GetConn) -> Result<(), LemmyError> { - let conn = &mut *pool.get_conn().await?; +async fn apub_columns_2021_02_02(pool: &DbPool) -> Result<(), LemmyError> { + let conn = &mut get_conn(pool).await?; info!("Running apub_columns_2021_02_02"); { use lemmy_db_schema::schema::person::dsl::{inbox_url, person, shared_inbox_url}; @@ -332,7 +329,7 @@ async fn apub_columns_2021_02_02(mut pool: &mut impl GetConn) -> Result<(), Lemm /// 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( - mut pool: &mut impl GetConn, + pool: &DbPool, protocol_and_hostname: &str, ) -> Result<(), LemmyError> { info!("Running instance_actor_2021_09_29"); @@ -361,8 +358,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(mut pool: &mut impl GetConn) -> Result<(), LemmyError> { - let conn = &mut *pool.get_conn().await?; +async fn regenerate_public_keys_2022_07_05(pool: &DbPool) -> Result<(), LemmyError> { + let conn = &mut get_conn(pool).await?; info!("Running regenerate_public_keys_2022_07_05"); { @@ -416,7 +413,7 @@ async fn regenerate_public_keys_2022_07_05(mut pool: &mut impl GetConn) -> Resul /// 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( - mut pool: &mut impl GetConn, + pool: &DbPool, settings: &Settings, ) -> Result<(), LemmyError> { info!("Running initialize_local_site_2022_10_10");