use crate::schema::comment_like::dsl::*;
insert_into(comment_like)
.values(comment_like_form)
+ .on_conflict((comment_id, user_id))
+ .do_update()
+ .set(comment_like_form)
.get_result::<Self>(conn)
}
fn remove(conn: &PgConnection, user_id: i32, comment_id: i32) -> Result<usize, Error> {
use crate::schema::comment_saved::dsl::*;
insert_into(comment_saved)
.values(comment_saved_form)
+ .on_conflict((comment_id, user_id))
+ .do_update()
+ .set(comment_saved_form)
.get_result::<Self>(conn)
}
fn unsave(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<usize, Error> {
use crate::schema::community_follower::dsl::*;
insert_into(community_follower)
.values(community_follower_form)
+ .on_conflict((community_id, user_id))
+ .do_update()
+ .set(community_follower_form)
.get_result::<Self>(conn)
}
fn follow_accepted(conn: &PgConnection, community_id_: i32, user_id_: i32) -> Result<Self, Error>
use crate::schema::post_like::dsl::*;
insert_into(post_like)
.values(post_like_form)
+ .on_conflict((post_id, user_id))
+ .do_update()
+ .set(post_like_form)
.get_result::<Self>(conn)
}
fn remove(conn: &PgConnection, user_id: i32, post_id: i32) -> Result<usize, Error> {
use crate::schema::post_saved::dsl::*;
insert_into(post_saved)
.values(post_saved_form)
+ .on_conflict((post_id, user_id))
+ .do_update()
+ .set(post_saved_form)
.get_result::<Self>(conn)
}
fn unsave(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<usize, Error> {
fn create(conn: &PgConnection, user_mention_form: &UserMentionForm) -> Result<Self, Error> {
use crate::schema::user_mention::dsl::*;
+ // since the return here isnt utilized, we dont need to do an update
+ // but get_result doesnt return the existing row here
insert_into(user_mention)
.values(user_mention_form)
+ .on_conflict((recipient_id, comment_id))
+ .do_update()
+ .set(user_mention_form)
.get_result::<Self>(conn)
}
// Allow this to fail softly, since comment edits might re-update or replace it
// Let the uniqueness handle this fail
- match UserMention::create(&conn, &user_mention_form) {
- Ok(_mention) => (),
- Err(_e) => error!("{}", &_e),
- };
+ let _ = UserMention::create(&conn, &user_mention_form);
// Send an email to those users that have notifications on
if do_send_email && mention_user.send_notifications_to_email {