add comment

pull/3605/head
phiresky 2023-09-01 12:13:53 +00:00
parent 6e445ac581
commit c654ceeb06
4 changed files with 14 additions and 42 deletions

5
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -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<Utc>,
}
// https://vasilakisfil.social/blog/2020/05/09/rust-diesel-jsonb/
impl FromSql<Jsonb, Pg> for ActivitySendTargets {
fn from_sql(bytes: PgValue) -> diesel::deserialize::Result<Self> {
let value = <serde_json::Value as FromSql<Jsonb, Pg>>::from_sql(bytes)?;
Ok(serde_json::from_value(value)?)
}
}
impl ToSql<Jsonb, Pg> 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)
}
}

View File

@ -21,7 +21,12 @@ impl CommunityFollowerView {
published_since: chrono::DateTime<Utc>,
) -> Result<Vec<(CommunityId, DbUrl)>, 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)