mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-10 06:54:12 +00:00
* Switch from bb8 to deadpool. Fixes #2765 * Remove unecessary deadpool dependency. * Ignoring nodeinfo test.
This commit is contained in:
parent
8c0c1628e0
commit
209c8a9185
8 changed files with 42 additions and 33 deletions
41
Cargo.lock
generated
41
Cargo.lock
generated
|
@ -605,19 +605,6 @@ version = "0.13.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
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]]
|
[[package]]
|
||||||
name = "bcrypt"
|
name = "bcrypt"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
|
@ -1200,6 +1187,25 @@ dependencies = [
|
||||||
"parking_lot_core 0.9.4",
|
"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]]
|
[[package]]
|
||||||
name = "derive_builder"
|
name = "derive_builder"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
|
@ -1306,7 +1312,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "588383fa6d12fb17edf0fda88942222bbad070d185b5dcc3ac4d8354ce84b583"
|
checksum = "588383fa6d12fb17edf0fda88942222bbad070d185b5dcc3ac4d8354ce84b583"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"bb8",
|
"deadpool",
|
||||||
"diesel",
|
"diesel",
|
||||||
"futures",
|
"futures",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
@ -2471,7 +2477,6 @@ version = "0.17.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitypub_federation",
|
"activitypub_federation",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"bb8",
|
|
||||||
"bcrypt",
|
"bcrypt",
|
||||||
"chrono",
|
"chrono",
|
||||||
"diesel",
|
"diesel",
|
||||||
|
@ -4098,6 +4103,12 @@ dependencies = [
|
||||||
"tracing-opentelemetry 0.16.0",
|
"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]]
|
[[package]]
|
||||||
name = "retry-policies"
|
name = "retry-policies"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
|
|
|
@ -16,7 +16,7 @@ doctest = false
|
||||||
[features]
|
[features]
|
||||||
full = ["diesel", "diesel-derive-newtype", "diesel_migrations", "bcrypt", "lemmy_utils",
|
full = ["diesel", "diesel-derive-newtype", "diesel_migrations", "bcrypt", "lemmy_utils",
|
||||||
"activitypub_federation", "sha2", "regex", "once_cell", "serde_json", "diesel_ltree",
|
"activitypub_federation", "sha2", "regex", "once_cell", "serde_json", "diesel_ltree",
|
||||||
"diesel-async", "bb8"]
|
"diesel-async"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
|
@ -31,7 +31,7 @@ bcrypt = { workspace = true, optional = true }
|
||||||
diesel = { workspace = true, features = ["postgres","chrono", "serde_json"], optional = true }
|
diesel = { workspace = true, features = ["postgres","chrono", "serde_json"], optional = true }
|
||||||
diesel-derive-newtype = { workspace = true, optional = true }
|
diesel-derive-newtype = { workspace = true, optional = true }
|
||||||
diesel_migrations = { 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 }
|
sha2 = { workspace = true, optional = true }
|
||||||
regex = { workspace = true, optional = true }
|
regex = { workspace = true, optional = true }
|
||||||
once_cell = { workspace = true, optional = true }
|
once_cell = { workspace = true, optional = true }
|
||||||
|
@ -39,7 +39,6 @@ diesel_ltree = { workspace = true, optional = true }
|
||||||
typed-builder = { workspace = true }
|
typed-builder = { workspace = true }
|
||||||
async-trait = { workspace = true }
|
async-trait = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
bb8 = { version = "0.8.0", optional = true }
|
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
tracing-error = { workspace = true }
|
tracing-error = { workspace = true }
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ use crate::{
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use activitypub_federation::{core::object_id::ObjectId, traits::ApubObject};
|
use activitypub_federation::{core::object_id::ObjectId, traits::ApubObject};
|
||||||
use bb8::PooledConnection;
|
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{
|
use diesel::{
|
||||||
backend::Backend,
|
backend::Backend,
|
||||||
|
@ -19,7 +18,10 @@ use diesel::{
|
||||||
};
|
};
|
||||||
use diesel_async::{
|
use diesel_async::{
|
||||||
pg::AsyncPgConnection,
|
pg::AsyncPgConnection,
|
||||||
pooled_connection::{bb8::Pool, AsyncDieselConnectionManager},
|
pooled_connection::{
|
||||||
|
deadpool::{Object as PooledConnection, Pool},
|
||||||
|
AsyncDieselConnectionManager,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use diesel_migrations::EmbeddedMigrations;
|
use diesel_migrations::EmbeddedMigrations;
|
||||||
use lemmy_utils::{error::LemmyError, settings::structs::Settings};
|
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 type DbPool = Pool<AsyncPgConnection>;
|
||||||
|
|
||||||
pub async fn get_conn(
|
pub async fn get_conn(pool: &DbPool) -> Result<PooledConnection<AsyncPgConnection>, DieselError> {
|
||||||
pool: &DbPool,
|
|
||||||
) -> Result<PooledConnection<AsyncDieselConnectionManager<AsyncPgConnection>>, DieselError> {
|
|
||||||
pool.get().await.map_err(|e| QueryBuilderError(e.into()))
|
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 db_url = get_database_url(settings);
|
||||||
let pool_size = settings.map(|s| s.database.pool_size).unwrap_or(5);
|
let pool_size = settings.map(|s| s.database.pool_size).unwrap_or(5);
|
||||||
let manager = AsyncDieselConnectionManager::<AsyncPgConnection>::new(&db_url);
|
let manager = AsyncDieselConnectionManager::<AsyncPgConnection>::new(&db_url);
|
||||||
let pool = Pool::builder()
|
let pool = Pool::builder(manager).max_size(pool_size).build()?;
|
||||||
.max_size(pool_size)
|
|
||||||
.min_idle(Some(1))
|
|
||||||
.build(manager)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
// If there's no settings, that means its a unit test, and migrations need to be run
|
// If there's no settings, that means its a unit test, and migrations need to be run
|
||||||
if settings.is_none() {
|
if settings.is_none() {
|
||||||
|
|
|
@ -17,6 +17,6 @@ full = ["lemmy_db_schema/full", "diesel", "diesel-async"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lemmy_db_schema = { workspace = true }
|
lemmy_db_schema = { workspace = true }
|
||||||
diesel = { workspace = true, features = ["postgres","chrono","serde_json"], optional = 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 }
|
serde = { workspace = true }
|
||||||
typed-builder = { workspace = true }
|
typed-builder = { workspace = true }
|
||||||
|
|
|
@ -17,5 +17,5 @@ full = ["lemmy_db_schema/full", "diesel", "diesel-async"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lemmy_db_schema = { workspace = true }
|
lemmy_db_schema = { workspace = true }
|
||||||
diesel = { workspace = true, features = ["postgres","chrono","serde_json"], optional = 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 }
|
serde = { workspace = true }
|
||||||
|
|
|
@ -74,7 +74,7 @@ pub struct DatabaseConfig {
|
||||||
pub(super) database: String,
|
pub(super) database: String,
|
||||||
/// Maximum number of active sql connections
|
/// Maximum number of active sql connections
|
||||||
#[default(5)]
|
#[default(5)]
|
||||||
pub pool_size: u32,
|
pub pool_size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)]
|
#[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)]
|
||||||
|
|
|
@ -65,12 +65,14 @@ pub async fn start_lemmy_server() -> Result<(), LemmyError> {
|
||||||
|
|
||||||
let settings = SETTINGS.to_owned();
|
let settings = SETTINGS.to_owned();
|
||||||
|
|
||||||
// Set up the bb8 connection pool
|
// Run the DB migrations
|
||||||
let db_url = get_database_url(Some(&settings));
|
let db_url = get_database_url(Some(&settings));
|
||||||
run_migrations(&db_url);
|
run_migrations(&db_url);
|
||||||
|
|
||||||
// Run the migrations from code
|
// Set up the connection pool
|
||||||
let pool = build_db_pool(&settings).await?;
|
let pool = build_db_pool(&settings).await?;
|
||||||
|
|
||||||
|
// Run the Code-required migrations
|
||||||
run_advanced_migrations(&pool, &settings).await?;
|
run_advanced_migrations(&pool, &settings).await?;
|
||||||
|
|
||||||
// Initialize the secrets
|
// Initialize the secrets
|
||||||
|
|
|
@ -183,6 +183,7 @@ mod tests {
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
#[ignore]
|
||||||
async fn test_nodeinfo() {
|
async fn test_nodeinfo() {
|
||||||
let client = Client::builder().build().unwrap();
|
let client = Client::builder().build().unwrap();
|
||||||
let lemmy_ml_nodeinfo = client
|
let lemmy_ml_nodeinfo = client
|
||||||
|
|
Loading…
Reference in a new issue