diff --git a/crates/db_views/post/src/db_perf/mod.rs b/crates/db_views/post/src/db_perf/mod.rs index 1939347c0..4b96a68c8 100644 --- a/crates/db_views/post/src/db_perf/mod.rs +++ b/crates/db_views/post/src/db_perf/mod.rs @@ -21,7 +21,7 @@ use lemmy_db_schema::{ use lemmy_db_schema_file::{enums::PostSortType, schema::post}; use lemmy_utils::error::LemmyResult; use serial_test::serial; -use std::num::NonZeroU32; +use std::{fmt::Display, num::NonZeroU32, str::FromStr}; use url::Url; #[derive(Debug)] @@ -33,15 +33,25 @@ struct CmdArgs { explain_insertions: bool, } +fn get_option(suffix: &str, default: T) -> Result { + let name = format!("LEMMY_{suffix}"); + if let Some(value) = std::env::var_os(&name) { + value.to_string_lossy().parse() + } else { + println!("🔧 using default env var {name}={default}"); + Ok(default) + } +} + #[tokio::test] #[serial] async fn db_perf() -> LemmyResult<()> { let args = CmdArgs { - communities: 3.try_into()?, - people: 3.try_into()?, - posts: 100000.try_into()?, - read_post_pages: 0, - explain_insertions: false, + communities: get_option("COMMUNITIES", 3.try_into()?)?, + people: get_option("PEOPLE", 3.try_into()?)?, + posts: get_option("POSTS", 100000.try_into()?)?, + read_post_pages: get_option("READ_POST_PAGES", 0)?, + explain_insertions: get_option("EXPLAIN_INSERTIONS", false)?, }; let pool = &build_db_pool()?; let pool = &mut pool.into(); diff --git a/scripts/db_perf.sh b/scripts/db_perf.sh index 1d53e0d37..97109233c 100755 --- a/scripts/db_perf.sh +++ b/scripts/db_perf.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# This script runs crates/lemmy_db_perf/src/main.rs, which lets you see info related to database query performance, such as query plans. +# This script runs crates/db_views/post/src/db_perf/mod.rs, which lets you see info related to database query performance, such as query plans. set -e @@ -10,10 +10,10 @@ cd "$CWD/../" source scripts/start_dev_db.sh -export LEMMY_CONFIG_LOCATION=config/config.hjson +export LEMMY_CONFIG_LOCATION=$(pwd)/config/config.hjson export RUST_BACKTRACE=1 -cargo run --package lemmy_db_perf -- "$@" +cargo test -p lemmy_db_views_post --features full --no-fail-fast db_perf -- --nocapture pg_ctl stop --silent