This commit is contained in:
Dull Bananas 2024-06-16 19:57:04 +00:00
parent 35b0613c58
commit 83c5181e43
3 changed files with 18 additions and 55 deletions

View file

@ -567,7 +567,7 @@ BEGIN
END IF; END IF;
-- Set local apub URLs -- Set local apub URLs
IF NEW.local THEN IF NEW.local THEN
NEW.ap_id = coalesce(NEW.ap_id, r.local_url('/comment/' || id)); NEW.ap_id = coalesce(r.null_if_needs_replacement (NEW.ap_id), r.local_url('/comment/' || id));
END IF; END IF;
RETURN NEW; RETURN NEW;
END END
@ -585,7 +585,7 @@ CREATE FUNCTION r.community_change_values ()
BEGIN BEGIN
-- Set local apub URLs -- Set local apub URLs
IF NEW.local THEN IF NEW.local THEN
NEW.actor_id = coalesce(NEW.actor_id, r.local_url('/c/' || NEW.id::text)); 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.followers_url = coalesce(NEW.followers_url, NEW.actor_id || '/followers');
NEW.inbox_url = coalesce(NEW.inbox_url, NEW.actor_id || '/inbox'); NEW.inbox_url = coalesce(NEW.inbox_url, NEW.actor_id || '/inbox');
NEW.moderators_url = coalesce(NEW.moderators_url, NEW.actor_id || '/moderators'); NEW.moderators_url = coalesce(NEW.moderators_url, NEW.actor_id || '/moderators');
@ -608,9 +608,9 @@ CREATE FUNCTION r.person_change_values ()
BEGIN BEGIN
-- Set local apub URLs -- Set local apub URLs
IF NEW.local THEN IF NEW.local THEN
NEW.actor_id = coalesce(NEW.actor_id, r.local_url('/u/' || NEW.id::text)); 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.inbox_url = coalesce(NEW.inbox_url, NEW.actor_id || '/inbox');
NEW.shared_inbox_url = coalesce(NEW.shared_inbox_url, r.local_url('/inbox'); NEW.shared_inbox_url = coalesce(NEW.shared_inbox_url, r.local_url('/inbox'));
END IF; END IF;
RETURN NEW; RETURN NEW;
END END
@ -628,7 +628,7 @@ CREATE FUNCTION r.post_change_values ()
BEGIN BEGIN
-- Set local apub URLs -- Set local apub URLs
IF NEW.local THEN IF NEW.local THEN
NEW.ap_id = coalesce(NEW.ap_id, r.local_url('/post/' || NEW.id::text)); NEW.ap_id = coalesce(r.null_if_needs_replacement (NEW.ap_id), r.local_url('/post/' || NEW.id::text));
END IF; END IF;
RETURN NEW; RETURN NEW;
END END
@ -646,7 +646,7 @@ CREATE FUNCTION r.private_message_change_values ()
BEGIN BEGIN
-- Set local apub URLs -- Set local apub URLs
IF NEW.local THEN IF NEW.local THEN
NEW.ap_id = coalesce(NEW.ap_id, r.local_url('/private_message/' || NEW.id::text)); NEW.ap_id = coalesce(r.null_if_needs_replacement (NEW.ap_id), r.local_url('/private_message/' || NEW.id::text));
END IF; END IF;
RETURN NEW; RETURN NEW;
END END

View file

@ -64,6 +64,11 @@ CREATE FUNCTION r.local_url (url_path text)
RETURN ( RETURN (
current_setting ('lemmy.protocol_and_hostname') || url_path); 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 -- This function creates statement-level triggers for all operation types. It's designed this way
-- because of these limitations: -- because of these limitations:
-- * A trigger that uses transition tables can only handle 1 operation type. -- * A trigger that uses transition tables can only handle 1 operation type.

View file

@ -10,13 +10,6 @@ use diesel::{
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_api_common::{ use lemmy_api_common::{
lemmy_db_views::structs::SiteView, lemmy_db_views::structs::SiteView,
utils::{
generate_followers_url,
generate_inbox_url,
generate_local_apub_endpoint,
generate_shared_inbox_url,
EndpointType,
},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{ source::{
@ -66,7 +59,7 @@ async fn user_updates_2020_04_02(
info!("Running user_updates_2020_04_02"); info!("Running user_updates_2020_04_02");
// Update the actor_id, private_key, and public_key, last_refreshed_at // Update the actor_id (in trigger), private_key, and public_key, last_refreshed_at
let incorrect_persons = person let incorrect_persons = person
.filter(actor_id.like("http://changeme%")) .filter(actor_id.like("http://changeme%"))
.filter(local.eq(true)) .filter(local.eq(true))
@ -77,11 +70,6 @@ async fn user_updates_2020_04_02(
let keypair = generate_actor_keypair()?; let keypair = generate_actor_keypair()?;
let form = PersonUpdateForm { let form = PersonUpdateForm {
actor_id: Some(generate_local_apub_endpoint(
EndpointType::Person,
&cperson.name,
protocol_and_hostname,
)?),
private_key: Some(Some(keypair.private_key)), private_key: Some(Some(keypair.private_key)),
public_key: Some(keypair.public_key), public_key: Some(keypair.public_key),
last_refreshed_at: Some(naive_now()), last_refreshed_at: Some(naive_now()),
@ -105,7 +93,7 @@ async fn community_updates_2020_04_02(
info!("Running community_updates_2020_04_02"); info!("Running community_updates_2020_04_02");
// Update the actor_id, private_key, and public_key, last_refreshed_at // Update the actor_id (in trigger), private_key, and public_key, last_refreshed_at
let incorrect_communities = community let incorrect_communities = community
.filter(actor_id.like("http://changeme%")) .filter(actor_id.like("http://changeme%"))
.filter(local.eq(true)) .filter(local.eq(true))
@ -114,14 +102,8 @@ async fn community_updates_2020_04_02(
for ccommunity in &incorrect_communities { for ccommunity in &incorrect_communities {
let keypair = generate_actor_keypair()?; let keypair = generate_actor_keypair()?;
let community_actor_id = generate_local_apub_endpoint(
EndpointType::Community,
&ccommunity.name,
protocol_and_hostname,
)?;
let form = CommunityUpdateForm { let form = CommunityUpdateForm {
actor_id: Some(community_actor_id.clone()),
private_key: Some(Some(keypair.private_key)), private_key: Some(Some(keypair.private_key)),
public_key: Some(keypair.public_key), public_key: Some(keypair.public_key),
last_refreshed_at: Some(naive_now()), last_refreshed_at: Some(naive_now()),
@ -145,7 +127,7 @@ async fn post_updates_2020_04_03(
info!("Running post_updates_2020_04_03"); info!("Running post_updates_2020_04_03");
// Update the ap_id // Update the ap_id (in trigger)
let incorrect_posts = post let incorrect_posts = post
.filter(ap_id.like("http://changeme%")) .filter(ap_id.like("http://changeme%"))
.filter(local.eq(true)) .filter(local.eq(true))
@ -153,18 +135,10 @@ async fn post_updates_2020_04_03(
.await?; .await?;
for cpost in &incorrect_posts { for cpost in &incorrect_posts {
let apub_id = generate_local_apub_endpoint(
EndpointType::Post,
&cpost.id.to_string(),
protocol_and_hostname,
)?;
Post::update( Post::update(
pool, pool,
cpost.id, cpost.id,
&PostUpdateForm { &PostUpdateForm::default(),
ap_id: Some(apub_id),
..Default::default()
},
) )
.await?; .await?;
} }
@ -183,7 +157,7 @@ async fn comment_updates_2020_04_03(
info!("Running comment_updates_2020_04_03"); info!("Running comment_updates_2020_04_03");
// Update the ap_id // Update the ap_id (in trigger)
let incorrect_comments = comment let incorrect_comments = comment
.filter(ap_id.like("http://changeme%")) .filter(ap_id.like("http://changeme%"))
.filter(local.eq(true)) .filter(local.eq(true))
@ -191,18 +165,10 @@ async fn comment_updates_2020_04_03(
.await?; .await?;
for ccomment in &incorrect_comments { for ccomment in &incorrect_comments {
let apub_id = generate_local_apub_endpoint(
EndpointType::Comment,
&ccomment.id.to_string(),
protocol_and_hostname,
)?;
Comment::update( Comment::update(
pool, pool,
ccomment.id, ccomment.id,
&CommentUpdateForm { &CommentUpdateForm::default(),
ap_id: Some(apub_id),
..Default::default()
},
) )
.await?; .await?;
} }
@ -229,18 +195,10 @@ async fn private_message_updates_2020_05_05(
.await?; .await?;
for cpm in &incorrect_pms { for cpm in &incorrect_pms {
let apub_id = generate_local_apub_endpoint(
EndpointType::PrivateMessage,
&cpm.id.to_string(),
protocol_and_hostname,
)?;
PrivateMessage::update( PrivateMessage::update(
pool, pool,
cpm.id, cpm.id,
&PrivateMessageUpdateForm { &PrivateMessageUpdateForm::default(),
ap_id: Some(apub_id),
..Default::default()
},
) )
.await?; .await?;
} }