diff options
Diffstat (limited to 'server/src/db')
-rw-r--r-- | server/src/db/activity.rs | 24 | ||||
-rw-r--r-- | server/src/db/code_migrations.rs | 15 | ||||
-rw-r--r-- | server/src/db/comment.rs | 2 | ||||
-rw-r--r-- | server/src/db/community.rs | 2 | ||||
-rw-r--r-- | server/src/db/password_reset_request.rs | 8 | ||||
-rw-r--r-- | server/src/db/user.rs | 2 |
6 files changed, 35 insertions, 18 deletions
diff --git a/server/src/db/activity.rs b/server/src/db/activity.rs index ccd1e682..8c2b0c74 100644 --- a/server/src/db/activity.rs +++ b/server/src/db/activity.rs @@ -1,9 +1,9 @@ -use crate::{db::Crud, schema::activity}; +use crate::{blocking, db::Crud, schema::activity, DbPool, LemmyError}; use diesel::{dsl::*, result::Error, *}; -use failure::_core::fmt::Debug; use log::debug; use serde::{Deserialize, Serialize}; use serde_json::Value; +use std::fmt::Debug; #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[table_name = "activity"] @@ -55,12 +55,28 @@ impl Crud<ActivityForm> for Activity { } } -pub fn insert_activity<T>( +pub async fn insert_activity<T>( + user_id: i32, + data: T, + local: bool, + pool: &DbPool, +) -> Result<(), LemmyError> +where + T: Serialize + Debug + Send + 'static, +{ + blocking(pool, move |conn| { + do_insert_activity(conn, user_id, &data, local) + }) + .await??; + Ok(()) +} + +fn do_insert_activity<T>( conn: &PgConnection, user_id: i32, data: &T, local: bool, -) -> Result<(), failure::Error> +) -> Result<(), LemmyError> where T: Serialize + Debug, { diff --git a/server/src/db/code_migrations.rs b/server/src/db/code_migrations.rs index 6f1b656f..67e0c4dc 100644 --- a/server/src/db/code_migrations.rs +++ b/server/src/db/code_migrations.rs @@ -10,21 +10,22 @@ use crate::{ apub::{extensions::signatures::generate_actor_keypair, make_apub_endpoint, EndpointType}, db::Crud, naive_now, + LemmyError, }; use diesel::*; -use failure::Error; use log::info; -pub fn run_advanced_migrations(conn: &PgConnection) -> Result<(), Error> { +pub fn run_advanced_migrations(conn: &PgConnection) -> Result<(), LemmyError> { user_updates_2020_04_02(&conn)?; community_updates_2020_04_02(&conn)?; post_updates_2020_04_03(&conn)?; comment_updates_2020_04_03(&conn)?; private_message_updates_2020_05_05(&conn)?; + Ok(()) } -fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), Error> { +fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> { use crate::schema::user_::dsl::*; info!("Running user_updates_2020_04_02"); @@ -75,7 +76,7 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), Error> { Ok(()) } -fn community_updates_2020_04_02(conn: &PgConnection) -> Result<(), Error> { +fn community_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> { use crate::schema::community::dsl::*; info!("Running community_updates_2020_04_02"); @@ -119,7 +120,7 @@ fn community_updates_2020_04_02(conn: &PgConnection) -> Result<(), Error> { Ok(()) } -fn post_updates_2020_04_03(conn: &PgConnection) -> Result<(), Error> { +fn post_updates_2020_04_03(conn: &PgConnection) -> Result<(), LemmyError> { use crate::schema::post::dsl::*; info!("Running post_updates_2020_04_03"); @@ -143,7 +144,7 @@ fn post_updates_2020_04_03(conn: &PgConnection) -> Result<(), Error> { Ok(()) } -fn comment_updates_2020_04_03(conn: &PgConnection) -> Result<(), Error> { +fn comment_updates_2020_04_03(conn: &PgConnection) -> Result<(), LemmyError> { use crate::schema::comment::dsl::*; info!("Running comment_updates_2020_04_03"); @@ -167,7 +168,7 @@ fn comment_updates_2020_04_03(conn: &PgConnection) -> Result<(), Error> { Ok(()) } -fn private_message_updates_2020_05_05(conn: &PgConnection) -> Result<(), Error> { +fn private_message_updates_2020_05_05(conn: &PgConnection) -> Result<(), LemmyError> { use crate::schema::private_message::dsl::*; info!("Running private_message_updates_2020_05_05"); diff --git a/server/src/db/comment.rs b/server/src/db/comment.rs index 8a2aa889..7e76770f 100644 --- a/server/src/db/comment.rs +++ b/server/src/db/comment.rs @@ -12,7 +12,7 @@ use crate::{ // ) // SELECT * FROM MyTree; -#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[belongs_to(Post)] #[table_name = "comment"] pub struct Comment { diff --git a/server/src/db/community.rs b/server/src/db/community.rs index 38ad07fc..461ba473 100644 --- a/server/src/db/community.rs +++ b/server/src/db/community.rs @@ -5,7 +5,7 @@ use crate::{ use diesel::{dsl::*, result::Error, *}; use serde::{Deserialize, Serialize}; -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[table_name = "community"] pub struct Community { pub id: i32, diff --git a/server/src/db/password_reset_request.rs b/server/src/db/password_reset_request.rs index b92d70ed..4a071f07 100644 --- a/server/src/db/password_reset_request.rs +++ b/server/src/db/password_reset_request.rs @@ -50,8 +50,8 @@ impl Crud<PasswordResetRequestForm> for PasswordResetRequest { impl PasswordResetRequest { pub fn create_token(conn: &PgConnection, from_user_id: i32, token: &str) -> Result<Self, Error> { let mut hasher = Sha256::new(); - hasher.input(token); - let token_hash: String = PasswordResetRequest::bytes_to_hex(hasher.result().to_vec()); + hasher.update(token); + let token_hash: String = PasswordResetRequest::bytes_to_hex(hasher.finalize().to_vec()); let form = PasswordResetRequestForm { user_id: from_user_id, @@ -62,8 +62,8 @@ impl PasswordResetRequest { } pub fn read_from_token(conn: &PgConnection, token: &str) -> Result<Self, Error> { let mut hasher = Sha256::new(); - hasher.input(token); - let token_hash: String = PasswordResetRequest::bytes_to_hex(hasher.result().to_vec()); + hasher.update(token); + let token_hash: String = PasswordResetRequest::bytes_to_hex(hasher.finalize().to_vec()); password_reset_request .filter(token_encrypted.eq(token_hash)) .filter(published.gt(now - 1.days())) diff --git a/server/src/db/user.rs b/server/src/db/user.rs index eaf9d292..4ca0a041 100644 --- a/server/src/db/user.rs +++ b/server/src/db/user.rs @@ -10,7 +10,7 @@ use diesel::{dsl::*, result::Error, *}; use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation}; use serde::{Deserialize, Serialize}; -#[derive(Queryable, Identifiable, PartialEq, Debug)] +#[derive(Clone, Queryable, Identifiable, PartialEq, Debug)] #[table_name = "user_"] pub struct User_ { pub id: i32, |