diff --git a/crates/db_schema/src/impls/actor_language.rs b/crates/db_schema/src/impls/actor_language.rs index 5c4e252d4..2e80b0680 100644 --- a/crates/db_schema/src/impls/actor_language.rs +++ b/crates/db_schema/src/impls/actor_language.rs @@ -96,16 +96,18 @@ impl LocalUserLanguage { .execute(conn) .await?; - for l in lang_ids { - let form = LocalUserLanguageForm { + let forms = lang_ids + .into_iter() + .map(|l| LocalUserLanguageForm { local_user_id: for_local_user_id, language_id: l, - }; - insert_into(local_user_language) - .values(form) - .get_result::(conn) - .await?; - } + }) + .collect::>(); + + insert_into(local_user_language) + .values(forms) + .execute(conn) + .await?; Ok(()) }) as _ }) diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 2b1179bee..b181edd7f 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -15,9 +15,11 @@ use diesel::{ pg::Pg, result::{ConnectionError, ConnectionResult, Error as DieselError, Error::QueryBuilderError}, serialize::{Output, ToSql}, + sql_query, sql_types::{Text, Timestamptz}, IntoSql, PgConnection, + RunQueryDsl, }; use diesel_async::{ pg::AsyncPgConnection, @@ -280,6 +282,12 @@ fn run_migrations(db_url: &str) { // Needs to be a sync connection let mut conn = PgConnection::establish(db_url).unwrap_or_else(|e| panic!("Error connecting to {db_url}: {e}")); + + // Disable auto_explain output for migrations + sql_query("SET auto_explain.log_min_duration = -1") + .execute(&mut conn) + .expect("failed to disable auto_explain"); + info!("Running Database migrations (This may take a long time)..."); let _ = &mut conn .run_pending_migrations(MIGRATIONS) diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 1d15c7c41..36dc0ee89 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -1433,7 +1433,7 @@ mod tests { let inserted_community = Community::create(pool, &community_form).await.unwrap(); let mut inserted_post_ids = vec![]; - let mut inserted_comment_ids = vec![]; + let mut comment_forms = vec![]; // Create 150 posts with varying non-correlating values for publish date, number of comments, and featured for comments in 0..10 { diff --git a/scripts/start_dev_db.sh b/scripts/start_dev_db.sh index f192defa6..c16969ed7 100644 --- a/scripts/start_dev_db.sh +++ b/scripts/start_dev_db.sh @@ -5,11 +5,15 @@ export PGHOST=$PWD export LEMMY_DATABASE_URL="postgresql://lemmy:password@/lemmy?host=$PWD" # If cluster exists, stop the server and delete the cluster -if [ -d $PGDATA ] +if [[ -d $PGDATA ]] then - # Prevent `stop` from failing if server already stopped - pg_ctl restart > /dev/null - pg_ctl stop + # Only stop server if it is running + (pg_ctl status > /dev/null) || pg_status_exit_code=$? + if [[ ${pg_status_exit_code} -ne 3 ]] + then + pg_ctl stop + fi + rm -rf $PGDATA fi @@ -17,7 +21,7 @@ fi initdb --username=postgres --auth=trust --no-instructions # Start server that only listens to socket in current directory -pg_ctl start --options="-c listen_addresses= -c unix_socket_directories=$PWD" > /dev/null +pg_ctl start --options="-c listen_addresses= -c unix_socket_directories=$PWD -c logging_collector=on -c session_preload_libraries=auto_explain -c auto_explain.log_min_duration=0 -c auto_explain.log_parameter_max_length=0 -c auto_explain.log_analyze=on -c enable_seqscan=off" > /dev/null # Setup database psql -c "CREATE USER lemmy WITH PASSWORD 'password' SUPERUSER;" -U postgres diff --git a/scripts/test.sh b/scripts/test.sh index cdfbf7611..7a8bd1c29 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -28,4 +28,3 @@ cargo test -p lemmy_utils --all-features --no-fail-fast # Add this to do printlns: -- --nocapture pg_ctl stop -rm -rf $PGDATA