From 5532b4a4d7ca2f3fe3135abe1de6ec79f30f95a8 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Mon, 3 Jan 2022 02:21:34 +0900 Subject: [PATCH] Ensure Post ap_url --- plume-models/src/posts.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 9a385db9..c41c6b2d 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -10,7 +10,7 @@ use activitypub::{ CustomObject, }; use chrono::{NaiveDateTime, TimeZone, Utc}; -use diesel::{self, BelongingToDsl, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; +use diesel::{self, BelongingToDsl, ExpressionMethods, QueryDsl, RunQueryDsl}; use once_cell::sync::Lazy; use plume_common::{ activity_pub::{ @@ -67,15 +67,15 @@ impl Post { find_by!(posts, find_by_ap_url, ap_url as &str); last!(posts); - pub fn insert(conn: &Connection, new: NewPost) -> Result { + pub fn insert(conn: &Connection, mut new: NewPost) -> Result { + if new.ap_url.is_empty() { + let blog = Blog::get(conn, new.blog_id)?; + new.ap_url = Self::ap_url(blog, &new.slug); + } diesel::insert_into(posts::table) .values(new) .execute(conn)?; - let mut post = Self::last(conn)?; - if post.ap_url.is_empty() { - post.ap_url = Self::ap_url(post.get_blog(conn)?, &post.slug); - let _: Post = post.save_changes(conn)?; - } + let post = Self::last(conn)?; if post.published { post.publish_published();