mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-09-09 16:08:49 -06:00
add comment
This commit is contained in:
parent
6e445ac581
commit
c654ceeb06
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -10,8 +10,9 @@ checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "activitypub_federation"
|
name = "activitypub_federation"
|
||||||
version = "0.5.0-beta.1"
|
version = "0.5.0-beta.3"
|
||||||
source = "git+https://github.com/phiresky/activitypub-federation-rust/?branch=raw-sending#da191f48bb2c1fcc3a8cc3d3f566182035ae25b1"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "509cbafa1b42e01b7ca76c26298814a6638825df4fd67aef2f4c9d36a39c2b6d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitystreams-kinds",
|
"activitystreams-kinds",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
|
@ -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 = { version = "=0.18.1", path = "./crates/db_views" }
|
||||||
lemmy_db_views_actor = { version = "=0.18.1", path = "./crates/db_views_actor" }
|
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" }
|
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",
|
"actix-web",
|
||||||
], git = "https://github.com/phiresky/activitypub-federation-rust/", branch = "raw-sending" }
|
] }
|
||||||
diesel = "2.1.0"
|
diesel = "2.1.0"
|
||||||
diesel_migrations = "2.1.0"
|
diesel_migrations = "2.1.0"
|
||||||
diesel-async = "0.3.1"
|
diesel-async = "0.3.1"
|
||||||
|
@ -3,29 +3,12 @@ use crate::{
|
|||||||
schema::sent_activity,
|
schema::sent_activity,
|
||||||
};
|
};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use diesel::{
|
use diesel::{sql_types::Nullable, Queryable};
|
||||||
deserialize::FromSql,
|
|
||||||
pg::{Pg, PgValue},
|
|
||||||
serialize::{Output, ToSql},
|
|
||||||
sql_types::{Jsonb, Nullable},
|
|
||||||
Queryable,
|
|
||||||
};
|
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::{collections::HashSet, fmt::Debug, io::Write};
|
use std::{collections::HashSet, fmt::Debug};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[derive(
|
#[derive(FromSqlRow, PartialEq, Eq, Debug, Default, Clone)]
|
||||||
FromSqlRow,
|
|
||||||
PartialEq,
|
|
||||||
Eq,
|
|
||||||
AsExpression,
|
|
||||||
serde::Serialize,
|
|
||||||
serde::Deserialize,
|
|
||||||
Debug,
|
|
||||||
Default,
|
|
||||||
Clone,
|
|
||||||
)]
|
|
||||||
#[diesel(sql_type = Jsonb)]
|
|
||||||
/// describes where an activity should be sent
|
/// describes where an activity should be sent
|
||||||
pub struct ActivitySendTargets {
|
pub struct ActivitySendTargets {
|
||||||
/// send to these inboxes explicitly
|
/// send to these inboxes explicitly
|
||||||
@ -111,20 +94,3 @@ pub struct ReceivedActivity {
|
|||||||
pub ap_id: DbUrl,
|
pub ap_id: DbUrl,
|
||||||
pub published: DateTime<Utc>,
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -21,7 +21,12 @@ impl CommunityFollowerView {
|
|||||||
published_since: chrono::DateTime<Utc>,
|
published_since: chrono::DateTime<Utc>,
|
||||||
) -> Result<Vec<(CommunityId, DbUrl)>, Error> {
|
) -> Result<Vec<(CommunityId, DbUrl)>, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
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
|
community_follower::table
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
Loading…
Reference in New Issue
Block a user