partial reverts

pull/4797/head
Dull Bananas 2024-06-21 03:31:03 +00:00
parent e9b0c1ff3b
commit 62ba725b8c
3 changed files with 14 additions and 71 deletions

View File

@ -552,8 +552,7 @@ CREATE TRIGGER delete_follow
FOR EACH ROW
EXECUTE FUNCTION r.delete_follow_before_person ();
-- Triggers that change values before insert or update (they can't be for insert only, because regenerating
-- the values using update must be possible)
-- Triggers that change values before insert or update
CREATE FUNCTION r.comment_change_values ()
RETURNS TRIGGER
LANGUAGE plpgsql
@ -565,7 +564,7 @@ BEGIN
IF NOT (NEW.path ~ ('*.' || id)::lquery) THEN
NEW.path = NEW.path || id;
END IF;
-- Set local apub URLs
-- Set local ap_id
IF NEW.local THEN
NEW.ap_id = coalesce(r.null_if_needs_replacement (NEW.ap_id), r.local_url('/comment/' || id));
END IF;
@ -578,55 +577,12 @@ CREATE TRIGGER change_values
FOR EACH ROW
EXECUTE FUNCTION r.comment_change_values ();
CREATE FUNCTION r.community_change_values ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
-- Set local apub URLs
IF NEW.local THEN
NEW.actor_id = coalesce(r.null_if_needs_replacement (NEW.actor_id), r.local_url('/c/' || NEW.id::text));
NEW.followers_url = coalesce(NEW.followers_url, NEW.actor_id || '/followers');
NEW.inbox_url = coalesce(NEW.inbox_url, NEW.actor_id || '/inbox');
NEW.moderators_url = coalesce(NEW.moderators_url, NEW.actor_id || '/moderators');
NEW.featured_url = coalesce(NEW.featured_url, NEW.actor_id || '/featured');
NEW.shared_inbox_url = coalesce(NEW.shared_inbox_url, r.local_url('/inbox');
END IF;
RETURN NEW;
END
$$;
CREATE TRIGGER change_values
BEFORE INSERT OR UPDATE ON community
FOR EACH ROW
EXECUTE FUNCTION r.community_change_values ();
CREATE FUNCTION r.person_change_values ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
-- Set local apub URLs
IF NEW.local THEN
NEW.actor_id = coalesce(r.null_if_needs_replacement (NEW.actor_id), r.local_url('/u/' || NEW.id::text));
NEW.inbox_url = coalesce(NEW.inbox_url, NEW.actor_id || '/inbox');
NEW.shared_inbox_url = coalesce(NEW.shared_inbox_url, r.local_url('/inbox'));
END IF;
RETURN NEW;
END
$$;
CREATE TRIGGER change_values
BEFORE INSERT OR UPDATE ON person
FOR EACH ROW
EXECUTE FUNCTION r.person_change_values ();
CREATE FUNCTION r.post_change_values ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
-- Set local apub URLs
-- Set local ap_id
IF NEW.local THEN
NEW.ap_id = coalesce(r.null_if_needs_replacement (NEW.ap_id), r.local_url('/post/' || NEW.id::text));
END IF;
@ -635,7 +591,7 @@ END
$$;
CREATE TRIGGER change_values
BEFORE INSERT OR UPDATE ON post
BEFORE INSERT ON post
FOR EACH ROW
EXECUTE FUNCTION r.post_change_values ();
@ -644,7 +600,7 @@ CREATE FUNCTION r.private_message_change_values ()
LANGUAGE plpgsql
AS $$
BEGIN
-- Set local apub URLs
-- Set local ap_id
IF NEW.local THEN
NEW.ap_id = coalesce(r.null_if_needs_replacement (NEW.ap_id), r.local_url('/private_message/' || NEW.id::text));
END IF;
@ -653,7 +609,7 @@ END
$$;
CREATE TRIGGER change_values
BEFORE INSERT OR UPDATE ON private_message
BEFORE INSERT ON private_message
FOR EACH ROW
EXECUTE FUNCTION r.private_message_change_values ();

View File

@ -64,11 +64,6 @@ CREATE FUNCTION r.local_url (url_path text)
RETURN (
current_setting ('lemmy.protocol_and_hostname') || url_path);
CREATE FUNCTION r.null_if_needs_replacement (t text)
RETURNS text
LANGUAGE sql
IMMUTABLE PARALLEL SAFE RETURN CASE WHEN t LIKE 'http://changeme%' THEN NULL ELSE t END CASE;
-- This function creates statement-level triggers for all operation types. It's designed this way
-- because of these limitations:
-- * A trigger that uses transition tables can only handle 1 operation type.

View File

@ -30,7 +30,7 @@ use diesel_async::{
AsyncDieselConnectionManager,
ManagerConfig,
},
RunQueryDsl,
SimpleAsyncConnection,
};
use futures_util::{future::BoxFuture, Future, FutureExt};
use i_love_jesus::CursorKey;
@ -352,18 +352,12 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConne
}
});
let mut conn = AsyncPgConnection::try_from(client).await?;
diesel::select((
// Change geqo_threshold back to default value if it was changed, so it's higher than the
// collapse limits
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
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)
// * 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
// for more complicated queries
conn
.batch_execute("SET geqo_threshold=12;SET from_collapse_limit=11;SET join_collapse_limit=11;")
.await
.map_err(ConnectionError::CouldntSetupConfiguration)?;
Ok(conn)
@ -491,7 +485,7 @@ static EMAIL_REGEX: Lazy<Regex> = Lazy::new(|| {
});
pub mod functions {
use diesel::sql_types::{BigInt, Bool, Text, Timestamptz};
use diesel::sql_types::{BigInt, Text, Timestamptz};
sql_function! {
#[sql_name = "r.hot_rank"]
@ -514,8 +508,6 @@ 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*";