This commit is contained in:
dull b 2023-12-15 20:25:38 +00:00
parent 70530a8ad2
commit 4fe1dd9af4
5 changed files with 28 additions and 15 deletions

View file

@ -96,16 +96,18 @@ impl LocalUserLanguage {
.execute(conn) .execute(conn)
.await?; .await?;
for l in lang_ids { let forms = lang_ids
let form = LocalUserLanguageForm { .into_iter()
.map(|l| LocalUserLanguageForm {
local_user_id: for_local_user_id, local_user_id: for_local_user_id,
language_id: l, language_id: l,
}; })
insert_into(local_user_language) .collect::<Vec<_>>();
.values(form)
.get_result::<Self>(conn) insert_into(local_user_language)
.await?; .values(forms)
} .execute(conn)
.await?;
Ok(()) Ok(())
}) as _ }) as _
}) })

View file

@ -15,9 +15,11 @@ use diesel::{
pg::Pg, pg::Pg,
result::{ConnectionError, ConnectionResult, Error as DieselError, Error::QueryBuilderError}, result::{ConnectionError, ConnectionResult, Error as DieselError, Error::QueryBuilderError},
serialize::{Output, ToSql}, serialize::{Output, ToSql},
sql_query,
sql_types::{Text, Timestamptz}, sql_types::{Text, Timestamptz},
IntoSql, IntoSql,
PgConnection, PgConnection,
RunQueryDsl,
}; };
use diesel_async::{ use diesel_async::{
pg::AsyncPgConnection, pg::AsyncPgConnection,
@ -280,6 +282,12 @@ fn run_migrations(db_url: &str) {
// Needs to be a sync connection // Needs to be a sync connection
let mut conn = let mut conn =
PgConnection::establish(db_url).unwrap_or_else(|e| panic!("Error connecting to {db_url}: {e}")); 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)..."); info!("Running Database migrations (This may take a long time)...");
let _ = &mut conn let _ = &mut conn
.run_pending_migrations(MIGRATIONS) .run_pending_migrations(MIGRATIONS)

View file

@ -1433,7 +1433,7 @@ mod tests {
let inserted_community = Community::create(pool, &community_form).await.unwrap(); let inserted_community = Community::create(pool, &community_form).await.unwrap();
let mut inserted_post_ids = vec![]; 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 // Create 150 posts with varying non-correlating values for publish date, number of comments, and featured
for comments in 0..10 { for comments in 0..10 {

View file

@ -5,11 +5,15 @@ export PGHOST=$PWD
export LEMMY_DATABASE_URL="postgresql://lemmy:password@/lemmy?host=$PWD" export LEMMY_DATABASE_URL="postgresql://lemmy:password@/lemmy?host=$PWD"
# If cluster exists, stop the server and delete the cluster # If cluster exists, stop the server and delete the cluster
if [ -d $PGDATA ] if [[ -d $PGDATA ]]
then then
# Prevent `stop` from failing if server already stopped # Only stop server if it is running
pg_ctl restart > /dev/null (pg_ctl status > /dev/null) || pg_status_exit_code=$?
pg_ctl stop if [[ ${pg_status_exit_code} -ne 3 ]]
then
pg_ctl stop
fi
rm -rf $PGDATA rm -rf $PGDATA
fi fi
@ -17,7 +21,7 @@ fi
initdb --username=postgres --auth=trust --no-instructions initdb --username=postgres --auth=trust --no-instructions
# Start server that only listens to socket in current directory # 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 # Setup database
psql -c "CREATE USER lemmy WITH PASSWORD 'password' SUPERUSER;" -U postgres psql -c "CREATE USER lemmy WITH PASSWORD 'password' SUPERUSER;" -U postgres

View file

@ -28,4 +28,3 @@ cargo test -p lemmy_utils --all-features --no-fail-fast
# Add this to do printlns: -- --nocapture # Add this to do printlns: -- --nocapture
pg_ctl stop pg_ctl stop
rm -rf $PGDATA