Add a fix for double posts / comments. #1080
This commit is contained in:
parent
c19dfdae64
commit
85cdcc5f13
2 changed files with 9 additions and 6 deletions
|
@ -341,7 +341,7 @@ async fn fetch_remote_community(
|
|||
Ok(community)
|
||||
}
|
||||
|
||||
fn upsert_post(post_form: &PostForm, conn: &PgConnection) -> Result<Post, LemmyError> {
|
||||
pub fn upsert_post(post_form: &PostForm, conn: &PgConnection) -> Result<Post, LemmyError> {
|
||||
let existing = Post::read_from_apub_id(conn, &post_form.ap_id);
|
||||
match existing {
|
||||
Err(NotFound {}) => Ok(Post::create(conn, &post_form)?),
|
||||
|
@ -376,7 +376,10 @@ pub async fn get_or_fetch_and_insert_post(
|
|||
}
|
||||
}
|
||||
|
||||
fn upsert_comment(comment_form: &CommentForm, conn: &PgConnection) -> Result<Comment, LemmyError> {
|
||||
pub fn upsert_comment(
|
||||
comment_form: &CommentForm,
|
||||
conn: &PgConnection,
|
||||
) -> Result<Comment, LemmyError> {
|
||||
let existing = Comment::read_from_apub_id(conn, &comment_form.ap_id);
|
||||
match existing {
|
||||
Err(NotFound {}) => Ok(Comment::create(conn, &comment_form)?),
|
||||
|
|
|
@ -4,6 +4,7 @@ use crate::{
|
|||
post::PostResponse,
|
||||
},
|
||||
apub::{
|
||||
fetcher::{upsert_comment, upsert_post},
|
||||
inbox::shared_inbox::{
|
||||
announce_if_community_is_local,
|
||||
get_user_from_activity,
|
||||
|
@ -26,11 +27,10 @@ use activitystreams::{activity::Create, base::AnyBase, object::Note, prelude::*}
|
|||
use actix_web::{client::Client, HttpResponse};
|
||||
use anyhow::Context;
|
||||
use lemmy_db::{
|
||||
comment::{Comment, CommentForm},
|
||||
comment::CommentForm,
|
||||
comment_view::CommentView,
|
||||
post::{Post, PostForm},
|
||||
post_view::PostView,
|
||||
Crud,
|
||||
};
|
||||
use lemmy_utils::{location_info, scrape_text_for_mentions};
|
||||
|
||||
|
@ -65,7 +65,7 @@ async fn receive_create_post(
|
|||
|
||||
let post = PostForm::from_apub(&page, client, pool, Some(user.actor_id()?)).await?;
|
||||
|
||||
let inserted_post = blocking(pool, move |conn| Post::create(conn, &post)).await??;
|
||||
let inserted_post = blocking(pool, move |conn| upsert_post(&post, conn)).await??;
|
||||
|
||||
// Refetch the view
|
||||
let inserted_post_id = inserted_post.id;
|
||||
|
@ -98,7 +98,7 @@ async fn receive_create_comment(
|
|||
|
||||
let comment = CommentForm::from_apub(¬e, client, pool, Some(user.actor_id()?)).await?;
|
||||
|
||||
let inserted_comment = blocking(pool, move |conn| Comment::create(conn, &comment)).await??;
|
||||
let inserted_comment = blocking(pool, move |conn| upsert_comment(&comment, conn)).await??;
|
||||
|
||||
let post_id = inserted_comment.post_id;
|
||||
let post = blocking(pool, move |conn| Post::read(conn, post_id)).await??;
|
||||
|
|
Loading…
Reference in a new issue