From a88d0e102f56e7e5b38ede56b7479f7ef23f8f87 Mon Sep 17 00:00:00 2001 From: Bat Date: Sat, 23 Jun 2018 13:40:10 +0100 Subject: [PATCH] Like: only compute ap_url once --- src/models/likes.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/models/likes.rs b/src/models/likes.rs index a8d6b6aa..f8d0e182 100644 --- a/src/models/likes.rs +++ b/src/models/likes.rs @@ -41,7 +41,11 @@ impl Like { pub fn update_ap_url(&self, conn: &PgConnection) { if self.ap_url.len() == 0 { diesel::update(self) - .set(likes::ap_url.eq(self.compute_id(conn))) + .set(likes::ap_url.eq(format!( + "{}/like/{}", + User::get(conn, self.user_id).unwrap().ap_url, + Post::get(conn, self.post_id).unwrap().ap_url + ))) .get_result::(conn).expect("Couldn't update AP URL"); } } @@ -65,21 +69,10 @@ impl Like { act.like_props.set_object_link(Post::get(conn, self.post_id).unwrap().into_id()).expect("Like::into_activity: object error"); act.object_props.set_to_link(Id::new(PUBLIC_VISIBILTY.to_string())).expect("Like::into_activity: to error"); act.object_props.set_cc_link_vec::(vec![]).expect("Like::into_activity: cc error"); - act.object_props.set_id_string(format!("{}/like/{}", - User::get(conn, self.user_id).unwrap().ap_url, - Post::get(conn, self.post_id).unwrap().ap_url - )).expect("Like::into_activity: id error"); + act.object_props.set_id_string(self.ap_url.clone()).expect("Like::into_activity: id error"); act } - - pub fn compute_id(&self, conn: &PgConnection) -> String { - format!( - "{}/like/{}", - User::get(conn, self.user_id).unwrap().ap_url, - Post::get(conn, self.post_id).unwrap().ap_url - ) - } } impl FromActivity for Like {