From: Dessalines Date: Tue, 28 Feb 2023 21:45:37 +0000 (-0500) Subject: Switch from bb8 to deadpool. Fixes #2765 (#2768) X-Git-Url: http://these/git/%7B%60/feeds/front/static/%7BfrontRss%7D?a=commitdiff_plain;h=209c8a91856d089acd12ac36b45d8019d433b2a7;p=lemmy.git Switch from bb8 to deadpool. Fixes #2765 (#2768) * Switch from bb8 to deadpool. Fixes #2765 * Remove unecessary deadpool dependency. * Ignoring nodeinfo test. --- diff --git a/Cargo.lock b/Cargo.lock index 260b8c94..10dac040 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -605,19 +605,6 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[package]] -name = "bb8" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1627eccf3aa91405435ba240be23513eeca466b5dc33866422672264de061582" -dependencies = [ - "async-trait", - "futures-channel", - "futures-util", - "parking_lot 0.12.1", - "tokio", -] - [[package]] name = "bcrypt" version = "0.13.0" @@ -1200,6 +1187,25 @@ dependencies = [ "parking_lot_core 0.9.4", ] +[[package]] +name = "deadpool" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "421fe0f90f2ab22016f32a9881be5134fdd71c65298917084b0c7477cbc3856e" +dependencies = [ + "async-trait", + "deadpool-runtime", + "num_cpus", + "retain_mut", + "tokio", +] + +[[package]] +name = "deadpool-runtime" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaa37046cc0f6c3cc6090fbdbf73ef0b8ef4cfcc37f6befc0020f63e8cf121e1" + [[package]] name = "derive_builder" version = "0.10.2" @@ -1306,7 +1312,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "588383fa6d12fb17edf0fda88942222bbad070d185b5dcc3ac4d8354ce84b583" dependencies = [ "async-trait", - "bb8", + "deadpool", "diesel", "futures", "tokio", @@ -2471,7 +2477,6 @@ version = "0.17.1" dependencies = [ "activitypub_federation", "async-trait", - "bb8", "bcrypt", "chrono", "diesel", @@ -4098,6 +4103,12 @@ dependencies = [ "tracing-opentelemetry 0.16.0", ] +[[package]] +name = "retain_mut" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4389f1d5789befaf6029ebd9f7dac4af7f7e3d61b69d4f30e2ac02b57e7712b0" + [[package]] name = "retry-policies" version = "0.1.1" diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index 83a32ba3..0983aa37 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -16,7 +16,7 @@ doctest = false [features] full = ["diesel", "diesel-derive-newtype", "diesel_migrations", "bcrypt", "lemmy_utils", "activitypub_federation", "sha2", "regex", "once_cell", "serde_json", "diesel_ltree", - "diesel-async", "bb8"] + "diesel-async"] [dependencies] chrono = { workspace = true } @@ -31,7 +31,7 @@ bcrypt = { workspace = true, optional = true } diesel = { workspace = true, features = ["postgres","chrono", "serde_json"], optional = true } diesel-derive-newtype = { workspace = true, optional = true } diesel_migrations = { workspace = true, optional = true } -diesel-async = { workspace = true, features = ["postgres", "bb8"], optional = true } +diesel-async = { workspace = true, features = ["postgres", "deadpool"], optional = true } sha2 = { workspace = true, optional = true } regex = { workspace = true, optional = true } once_cell = { workspace = true, optional = true } @@ -39,7 +39,6 @@ diesel_ltree = { workspace = true, optional = true } typed-builder = { workspace = true } async-trait = { workspace = true } tokio = { workspace = true } -bb8 = { version = "0.8.0", optional = true } tracing = { workspace = true } tracing-error = { workspace = true } diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 71a0875d..9e3a3f41 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -6,7 +6,6 @@ use crate::{ SortType, }; use activitypub_federation::{core::object_id::ObjectId, traits::ApubObject}; -use bb8::PooledConnection; use chrono::NaiveDateTime; use diesel::{ backend::Backend, @@ -19,7 +18,10 @@ use diesel::{ }; use diesel_async::{ pg::AsyncPgConnection, - pooled_connection::{bb8::Pool, AsyncDieselConnectionManager}, + pooled_connection::{ + deadpool::{Object as PooledConnection, Pool}, + AsyncDieselConnectionManager, + }, }; use diesel_migrations::EmbeddedMigrations; use lemmy_utils::{error::LemmyError, settings::structs::Settings}; @@ -34,9 +36,7 @@ pub const FETCH_LIMIT_MAX: i64 = 50; pub type DbPool = Pool; -pub async fn get_conn( - pool: &DbPool, -) -> Result>, DieselError> { +pub async fn get_conn(pool: &DbPool) -> Result, DieselError> { pool.get().await.map_err(|e| QueryBuilderError(e.into())) } @@ -135,11 +135,7 @@ async fn build_db_pool_settings_opt(settings: Option<&Settings>) -> Result::new(&db_url); - let pool = Pool::builder() - .max_size(pool_size) - .min_idle(Some(1)) - .build(manager) - .await?; + let pool = Pool::builder(manager).max_size(pool_size).build()?; // If there's no settings, that means its a unit test, and migrations need to be run if settings.is_none() { diff --git a/crates/db_views_actor/Cargo.toml b/crates/db_views_actor/Cargo.toml index abec875b..8b16bb4c 100644 --- a/crates/db_views_actor/Cargo.toml +++ b/crates/db_views_actor/Cargo.toml @@ -17,6 +17,6 @@ full = ["lemmy_db_schema/full", "diesel", "diesel-async"] [dependencies] lemmy_db_schema = { workspace = true } diesel = { workspace = true, features = ["postgres","chrono","serde_json"], optional = true } -diesel-async = { workspace = true, features = ["postgres", "bb8"], optional = true } +diesel-async = { workspace = true, features = ["postgres", "deadpool"], optional = true } serde = { workspace = true } typed-builder = { workspace = true } diff --git a/crates/db_views_moderator/Cargo.toml b/crates/db_views_moderator/Cargo.toml index ad0bf167..fe79fdd2 100644 --- a/crates/db_views_moderator/Cargo.toml +++ b/crates/db_views_moderator/Cargo.toml @@ -17,5 +17,5 @@ full = ["lemmy_db_schema/full", "diesel", "diesel-async"] [dependencies] lemmy_db_schema = { workspace = true } diesel = { workspace = true, features = ["postgres","chrono","serde_json"], optional = true } -diesel-async = { workspace = true, features = ["postgres", "bb8"], optional = true } +diesel-async = { workspace = true, features = ["postgres", "deadpool"], optional = true } serde = { workspace = true } diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index e5dac10d..9d46dbe8 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -74,7 +74,7 @@ pub struct DatabaseConfig { pub(super) database: String, /// Maximum number of active sql connections #[default(5)] - pub pool_size: u32, + pub pool_size: usize, } #[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)] diff --git a/src/lib.rs b/src/lib.rs index ce44739c..d30b214c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,12 +65,14 @@ pub async fn start_lemmy_server() -> Result<(), LemmyError> { let settings = SETTINGS.to_owned(); - // Set up the bb8 connection pool + // Run the DB migrations let db_url = get_database_url(Some(&settings)); run_migrations(&db_url); - // Run the migrations from code + // Set up the connection pool let pool = build_db_pool(&settings).await?; + + // Run the Code-required migrations run_advanced_migrations(&pool, &settings).await?; // Initialize the secrets diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index 4fc85b8f..fd5c074d 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -183,6 +183,7 @@ mod tests { use reqwest::Client; #[tokio::test] + #[ignore] async fn test_nodeinfo() { let client = Client::builder().build().unwrap(); let lemmy_ml_nodeinfo = client