mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-09-02 11:13:51 +00:00
parent
0a22fac562
commit
6accb4110d
2 changed files with 19 additions and 9 deletions
|
@ -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<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]
|
||||
#[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();
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue