From c654ceeb06e90fb2c02da70b06a002fe53940bcf Mon Sep 17 00:00:00 2001 From: phiresky Date: Fri, 1 Sep 2023 12:13:53 +0000 Subject: [PATCH] add comment --- Cargo.lock | 5 ++- Cargo.toml | 4 +- crates/db_schema/src/source/activity.rs | 40 ++----------------- .../src/community_follower_view.rs | 7 +++- 4 files changed, 14 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76f6ff698..48f024791 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,8 +10,9 @@ checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" [[package]] name = "activitypub_federation" -version = "0.5.0-beta.1" -source = "git+https://github.com/phiresky/activitypub-federation-rust/?branch=raw-sending#da191f48bb2c1fcc3a8cc3d3f566182035ae25b1" +version = "0.5.0-beta.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "509cbafa1b42e01b7ca76c26298814a6638825df4fd67aef2f4c9d36a39c2b6d" dependencies = [ "activitystreams-kinds", "actix-web", diff --git a/Cargo.toml b/Cargo.toml index f48a75b4d..49db43fce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,9 +68,9 @@ lemmy_routes = { version = "=0.18.1", path = "./crates/routes" } lemmy_db_views = { version = "=0.18.1", path = "./crates/db_views" } lemmy_db_views_actor = { version = "=0.18.1", path = "./crates/db_views_actor" } lemmy_db_views_moderator = { version = "=0.18.1", path = "./crates/db_views_moderator" } -activitypub_federation = { version = "0.5.0-beta.1", default-features = false, features = [ +activitypub_federation = { version = "0.5.0-beta.3", default-features = false, features = [ "actix-web", -], git = "https://github.com/phiresky/activitypub-federation-rust/", branch = "raw-sending" } +] } diesel = "2.1.0" diesel_migrations = "2.1.0" diesel-async = "0.3.1" diff --git a/crates/db_schema/src/source/activity.rs b/crates/db_schema/src/source/activity.rs index 040dfd73f..fc4bb0ec5 100644 --- a/crates/db_schema/src/source/activity.rs +++ b/crates/db_schema/src/source/activity.rs @@ -3,29 +3,12 @@ use crate::{ schema::sent_activity, }; use chrono::{DateTime, Utc}; -use diesel::{ - deserialize::FromSql, - pg::{Pg, PgValue}, - serialize::{Output, ToSql}, - sql_types::{Jsonb, Nullable}, - Queryable, -}; +use diesel::{sql_types::Nullable, Queryable}; use serde_json::Value; -use std::{collections::HashSet, fmt::Debug, io::Write}; +use std::{collections::HashSet, fmt::Debug}; use url::Url; -#[derive( - FromSqlRow, - PartialEq, - Eq, - AsExpression, - serde::Serialize, - serde::Deserialize, - Debug, - Default, - Clone, -)] -#[diesel(sql_type = Jsonb)] +#[derive(FromSqlRow, PartialEq, Eq, Debug, Default, Clone)] /// describes where an activity should be sent pub struct ActivitySendTargets { /// send to these inboxes explicitly @@ -111,20 +94,3 @@ pub struct ReceivedActivity { pub ap_id: DbUrl, pub published: DateTime, } - -// https://vasilakisfil.social/blog/2020/05/09/rust-diesel-jsonb/ -impl FromSql for ActivitySendTargets { - fn from_sql(bytes: PgValue) -> diesel::deserialize::Result { - let value = >::from_sql(bytes)?; - Ok(serde_json::from_value(value)?) - } -} - -impl ToSql for ActivitySendTargets { - fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> diesel::serialize::Result { - out.write_all(&[1])?; - serde_json::to_writer(out, self) - .map(|_| diesel::serialize::IsNull::No) - .map_err(Into::into) - } -} diff --git a/crates/db_views_actor/src/community_follower_view.rs b/crates/db_views_actor/src/community_follower_view.rs index 78d147d3a..b2eeda29e 100644 --- a/crates/db_views_actor/src/community_follower_view.rs +++ b/crates/db_views_actor/src/community_follower_view.rs @@ -21,7 +21,12 @@ impl CommunityFollowerView { published_since: chrono::DateTime, ) -> Result, Error> { let conn = &mut get_conn(pool).await?; - // todo: in most cases this will fetch the same url many times (the shared inbox url) + // In most cases this will fetch the same url many times (the shared inbox url) + // PG will only send a single copy to rust, but it has to scan through all follower rows (same as it was before). + // So on the PG side it would be possible to optimize this further by adding e.g. a new table community_followed_instances (community_id, instance_id) + // that would work for all instances that support fully shared inboxes. + // It would be a bit more complicated though to keep it in sync. + community_follower::table .inner_join(community::table) .inner_join(person::table)