Fix db_perf.sh (#5815)

* db_perf.sh

* get_option function
This commit is contained in:
dullbananas 2025-06-22 08:56:10 -07:00 committed by GitHub
parent 0a22fac562
commit 6accb4110d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 9 deletions

View file

@ -21,7 +21,7 @@ use lemmy_db_schema::{
use lemmy_db_schema_file::{enums::PostSortType, schema::post}; use lemmy_db_schema_file::{enums::PostSortType, schema::post};
use lemmy_utils::error::LemmyResult; use lemmy_utils::error::LemmyResult;
use serial_test::serial; use serial_test::serial;
use std::num::NonZeroU32; use std::{fmt::Display, num::NonZeroU32, str::FromStr};
use url::Url; use url::Url;
#[derive(Debug)] #[derive(Debug)]
@ -33,15 +33,25 @@ struct CmdArgs {
explain_insertions: bool, explain_insertions: bool,
} }
fn get_option<T: FromStr + Display>(suffix: &str, default: T) -> Result<T, T::Err> {
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] #[tokio::test]
#[serial] #[serial]
async fn db_perf() -> LemmyResult<()> { async fn db_perf() -> LemmyResult<()> {
let args = CmdArgs { let args = CmdArgs {
communities: 3.try_into()?, communities: get_option("COMMUNITIES", 3.try_into()?)?,
people: 3.try_into()?, people: get_option("PEOPLE", 3.try_into()?)?,
posts: 100000.try_into()?, posts: get_option("POSTS", 100000.try_into()?)?,
read_post_pages: 0, read_post_pages: get_option("READ_POST_PAGES", 0)?,
explain_insertions: false, explain_insertions: get_option("EXPLAIN_INSERTIONS", false)?,
}; };
let pool = &build_db_pool()?; let pool = &build_db_pool()?;
let pool = &mut pool.into(); let pool = &mut pool.into();

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/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 set -e
@ -10,10 +10,10 @@ cd "$CWD/../"
source scripts/start_dev_db.sh 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 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 pg_ctl stop --silent