Update utils.rs

This commit is contained in:
dullbananas 2024-06-10 14:13:12 -07:00 committed by GitHub
parent 1f30b38ca2
commit 87e86825f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -340,12 +340,18 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConne
}
});
let mut conn = AsyncPgConnection::try_from(client).await?;
// * Change geqo_threshold back to default value if it was changed, so it's higher than the
diesel::select((
// Change geqo_threshold back to default value if it was changed, so it's higher than the
// collapse limits
// * Change collapse limits from 8 to 11 so the query planner can find a better table join order
functions::set_config("geqo_threshold", "12", false),
// Change collapse limits from 8 to 11 so the query planner can find a better table join order
// for more complicated queries
conn
.batch_execute("SET geqo_threshold=12;SET from_collapse_limit=11;SET join_collapse_limit=11;")
functions::set_config("from_collapse_limit", "11", false),
functions::set_config("join_collapse_limit", "11", false),
// * Set `lemmy.protocol_and_hostname` so triggers can use it
functions::set_config("lemmy.protocol_and_hostname", SETTINGS.get_protocol_and_hostname(), false),
))
.execute(&mut conn)
.await
.map_err(ConnectionError::CouldntSetupConfiguration)?;
Ok(conn)
@ -473,7 +479,7 @@ static EMAIL_REGEX: Lazy<Regex> = Lazy::new(|| {
});
pub mod functions {
use diesel::sql_types::{BigInt, Text, Timestamptz};
use diesel::sql_types::{BigInt, Bool, Text, Timestamptz};
sql_function! {
#[sql_name = "r.hot_rank"]
@ -496,6 +502,8 @@ pub mod functions {
// really this function is variadic, this just adds the two-argument version
sql_function!(fn coalesce<T: diesel::sql_types::SqlType + diesel::sql_types::SingleValue>(x: diesel::sql_types::Nullable<T>, y: T) -> T);
sql_function(fn set_config(setting_name: Text, new_value: Text, is_local: Bool) -> Text);
}
pub const DELETED_REPLACEMENT_TEXT: &str = "*Permanently Deleted*";