Revert "Removing on_conflict as it may not work with table triggers (user_fast, etc)"

This reverts commit db7027a367.
This commit is contained in:
Dessalines 2020-10-07 19:08:06 -05:00
parent fd257a6d39
commit b4c730e537
5 changed files with 34 additions and 51 deletions

View file

@ -170,15 +170,13 @@ impl Comment {
} }
pub fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> { pub fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
let existing = Self::read_from_apub_id( use crate::schema::comment::dsl::*;
conn, insert_into(comment)
comment_form.ap_id.as_ref().unwrap_or(&"none".to_string()), .values(comment_form)
); .on_conflict(ap_id)
match existing { .do_update()
Err(NotFound {}) => Ok(Self::create(conn, &comment_form)?), .set(comment_form)
Ok(p) => Ok(Self::update(conn, p.id, &comment_form)?), .get_result::<Self>(conn)
Err(e) => Err(e),
}
} }
} }

View file

@ -166,18 +166,13 @@ impl Community {
} }
pub fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> { pub fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
let existing = Self::read_from_actor_id( use crate::schema::community::dsl::*;
conn, insert_into(community)
community_form .values(community_form)
.actor_id .on_conflict(actor_id)
.as_ref() .do_update()
.unwrap_or(&"none".to_string()), .set(community_form)
); .get_result::<Self>(conn)
match existing {
Err(NotFound {}) => Ok(Self::create(conn, &community_form)?),
Ok(p) => Ok(Self::update(conn, p.id, &community_form)?),
Err(e) => Err(e),
}
} }
} }

View file

@ -179,15 +179,13 @@ impl Post {
} }
pub fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error> { pub fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error> {
let existing = Self::read_from_apub_id( use crate::schema::post::dsl::*;
conn, insert_into(post)
post_form.ap_id.as_ref().unwrap_or(&"none".to_string()), .values(post_form)
); .on_conflict(ap_id)
match existing { .do_update()
Err(NotFound {}) => Ok(Self::create(conn, &post_form)?), .set(post_form)
Ok(p) => Ok(Self::update(conn, p.id, &post_form)?), .get_result::<Self>(conn)
Err(e) => Err(e),
}
} }
} }

View file

@ -124,18 +124,13 @@ impl PrivateMessage {
conn: &PgConnection, conn: &PgConnection,
private_message_form: &PrivateMessageForm, private_message_form: &PrivateMessageForm,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
let existing = Self::read_from_apub_id( use crate::schema::private_message::dsl::*;
conn, insert_into(private_message)
private_message_form .values(private_message_form)
.ap_id .on_conflict(ap_id)
.as_ref() .do_update()
.unwrap_or(&"none".to_string()), .set(private_message_form)
); .get_result::<Self>(conn)
match existing {
Err(NotFound {}) => Ok(Self::create(conn, &private_message_form)?),
Ok(p) => Ok(Self::update(conn, p.id, &private_message_form)?),
Err(e) => Err(e),
}
} }
} }

View file

@ -161,15 +161,12 @@ impl User_ {
} }
pub fn upsert(conn: &PgConnection, user_form: &UserForm) -> Result<User_, Error> { pub fn upsert(conn: &PgConnection, user_form: &UserForm) -> Result<User_, Error> {
let existing = Self::read_from_actor_id( insert_into(user_)
conn, .values(user_form)
user_form.actor_id.as_ref().unwrap_or(&"none".to_string()), .on_conflict(actor_id)
); .do_update()
match existing { .set(user_form)
Err(NotFound {}) => Ok(Self::create(conn, &user_form)?), .get_result::<Self>(conn)
Ok(p) => Ok(Self::update(conn, p.id, &user_form)?),
Err(e) => Err(e),
}
} }
} }