]> Untitled Git - lemmy.git/blobdiff - crates/db_schema/src/impls/person.rs
Cache & Optimize Woodpecker CI (#3450)
[lemmy.git] / crates / db_schema / src / impls / person.rs
index 5c23f8071a2adbd3eb973b6ae6d577a8f6bf6687..2e086dcb6d3f1cb9a8eda5ec61ec38ca9b142103 100644 (file)
@@ -19,7 +19,7 @@ impl Crud for Person {
   type InsertForm = PersonInsertForm;
   type UpdateForm = PersonUpdateForm;
   type IdType = PersonId;
-  async fn read(pool: &DbPool, person_id: PersonId) -> Result<Self, Error> {
+  async fn read(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Self, Error> {
     let conn = &mut get_conn(pool).await?;
     person::table
       .filter(person::deleted.eq(false))
@@ -27,13 +27,13 @@ impl Crud for Person {
       .first::<Self>(conn)
       .await
   }
-  async fn delete(pool: &DbPool, person_id: PersonId) -> Result<usize, Error> {
+  async fn delete(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<usize, Error> {
     let conn = &mut get_conn(pool).await?;
     diesel::delete(person::table.find(person_id))
       .execute(conn)
       .await
   }
-  async fn create(pool: &DbPool, form: &PersonInsertForm) -> Result<Self, Error> {
+  async fn create(pool: &mut DbPool<'_>, form: &PersonInsertForm) -> Result<Self, Error> {
     let conn = &mut get_conn(pool).await?;
     insert_into(person::table)
       .values(form)
@@ -41,7 +41,7 @@ impl Crud for Person {
       .await
   }
   async fn update(
-    pool: &DbPool,
+    pool: &mut DbPool<'_>,
     person_id: PersonId,
     form: &PersonUpdateForm,
   ) -> Result<Self, Error> {
@@ -57,7 +57,7 @@ impl Person {
   /// Update or insert the person.
   ///
   /// This is necessary for federation, because Activitypub doesnt distinguish between these actions.
-  pub async fn upsert(pool: &DbPool, form: &PersonInsertForm) -> Result<Self, Error> {
+  pub async fn upsert(pool: &mut DbPool<'_>, form: &PersonInsertForm) -> Result<Self, Error> {
     let conn = &mut get_conn(pool).await?;
     insert_into(person::table)
       .values(form)
@@ -67,7 +67,7 @@ impl Person {
       .get_result::<Self>(conn)
       .await
   }
-  pub async fn delete_account(pool: &DbPool, person_id: PersonId) -> Result<Person, Error> {
+  pub async fn delete_account(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Person, Error> {
     let conn = &mut get_conn(pool).await?;
 
     // Set the local user info to none
@@ -104,7 +104,10 @@ pub fn is_banned(banned_: bool, expires: Option<chrono::NaiveDateTime>) -> bool
 
 #[async_trait]
 impl ApubActor for Person {
-  async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result<Option<Self>, Error> {
+  async fn read_from_apub_id(
+    pool: &mut DbPool<'_>,
+    object_id: &DbUrl,
+  ) -> Result<Option<Self>, Error> {
     let conn = &mut get_conn(pool).await?;
     Ok(
       person::table
@@ -118,7 +121,7 @@ impl ApubActor for Person {
   }
 
   async fn read_from_name(
-    pool: &DbPool,
+    pool: &mut DbPool<'_>,
     from_name: &str,
     include_deleted: bool,
   ) -> Result<Person, Error> {
@@ -134,7 +137,7 @@ impl ApubActor for Person {
   }
 
   async fn read_from_name_and_domain(
-    pool: &DbPool,
+    pool: &mut DbPool<'_>,
     person_name: &str,
     for_domain: &str,
   ) -> Result<Person, Error> {
@@ -153,7 +156,7 @@ impl ApubActor for Person {
 #[async_trait]
 impl Followable for PersonFollower {
   type Form = PersonFollowerForm;
-  async fn follow(pool: &DbPool, form: &PersonFollowerForm) -> Result<Self, Error> {
+  async fn follow(pool: &mut DbPool<'_>, form: &PersonFollowerForm) -> Result<Self, Error> {
     use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id};
     let conn = &mut get_conn(pool).await?;
     insert_into(person_follower)
@@ -164,10 +167,10 @@ impl Followable for PersonFollower {
       .get_result::<Self>(conn)
       .await
   }
-  async fn follow_accepted(_: &DbPool, _: CommunityId, _: PersonId) -> Result<Self, Error> {
+  async fn follow_accepted(_: &mut DbPool<'_>, _: CommunityId, _: PersonId) -> Result<Self, Error> {
     unimplemented!()
   }
-  async fn unfollow(pool: &DbPool, form: &PersonFollowerForm) -> Result<usize, Error> {
+  async fn unfollow(pool: &mut DbPool<'_>, form: &PersonFollowerForm) -> Result<usize, Error> {
     use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id};
     let conn = &mut get_conn(pool).await?;
     diesel::delete(
@@ -182,7 +185,7 @@ impl Followable for PersonFollower {
 
 impl PersonFollower {
   pub async fn list_followers(
-    pool: &DbPool,
+    pool: &mut DbPool<'_>,
     for_person_id: PersonId,
   ) -> Result<Vec<Person>, Error> {
     let conn = &mut get_conn(pool).await?;
@@ -197,6 +200,9 @@ impl PersonFollower {
 
 #[cfg(test)]
 mod tests {
+  #![allow(clippy::unwrap_used)]
+  #![allow(clippy::indexing_slicing)]
+
   use crate::{
     source::{
       instance::Instance,
@@ -211,6 +217,7 @@ mod tests {
   #[serial]
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
+    let pool = &mut pool.into();
 
     let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
       .await
@@ -271,6 +278,7 @@ mod tests {
   #[serial]
   async fn follow() {
     let pool = &build_db_pool_for_tests().await;
+    let pool = &mut pool.into();
     let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
       .await
       .unwrap();