Switch from bb8 to deadpool. Fixes #2765 (#2768)

* Switch from bb8 to deadpool. Fixes #2765

* Remove unecessary deadpool dependency.

* Ignoring nodeinfo test.
This commit is contained in:
Dessalines 2023-02-28 16:45:37 -05:00 committed by GitHub
parent 8c0c1628e0
commit 209c8a9185
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 33 deletions

41
Cargo.lock generated
View file

@ -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"

View file

@ -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 }

View file

@ -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<AsyncPgConnection>;
pub async fn get_conn(
pool: &DbPool,
) -> Result<PooledConnection<AsyncDieselConnectionManager<AsyncPgConnection>>, DieselError> {
pub async fn get_conn(pool: &DbPool) -> Result<PooledConnection<AsyncPgConnection>, 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<DbPoo
let db_url = get_database_url(settings);
let pool_size = settings.map(|s| s.database.pool_size).unwrap_or(5);
let manager = AsyncDieselConnectionManager::<AsyncPgConnection>::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() {

View file

@ -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 }

View file

@ -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 }

View file

@ -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)]

View file

@ -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

View file

@ -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