From d7e380f83ed31a288ad81ab38cf5f21ef0c75b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mina=20Gali=C4=87?= Date: Thu, 27 Aug 2020 12:21:51 +0200 Subject: [PATCH] remove Searcher from Post::update() thereby decoupling the two systems (for updates, anyway) That means, consumers of Post need to update_document themselves! Post (in update) now only talks to the database) Tests for this will now be failing, as they haven't been touched yet --- plume-models/src/posts.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 0520d8ba..49cb2c41 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -1,7 +1,7 @@ use crate::{ ap_url, blogs::Blog, instance::Instance, medias::Media, mentions::Mention, post_authors::*, - safe_string::SafeString, schema::posts, search::Searcher, tags::*, timeline::*, users::User, - Connection, Error, PlumeRocket, Result, CONFIG, + safe_string::SafeString, schema::posts, search::Searcher, search::UpdateDocument, tags::*, + timeline::*, users::User, Connection, Error, PlumeRocket, Result, CONFIG, }; use activitypub::{ activity::{Create, Delete, Update}, @@ -19,6 +19,8 @@ use plume_common::{ }, utils::md_to_html, }; + +use riker::actors::*; use serde_json; use std::collections::HashSet; @@ -82,10 +84,9 @@ impl Post { Ok(post) } - pub fn update(&self, conn: &Connection, searcher: &Searcher) -> Result { + pub fn update(&self, conn: &Connection) -> Result { diesel::update(self).set(self).execute(conn)?; let post = Self::get(conn, self.id)?; - searcher.update_document(&post)?; Ok(post) } @@ -728,7 +729,7 @@ impl AsObject for PostUpdate { fn activity(self, c: &PlumeRocket, actor: User, _id: &str) -> Result<()> { let conn = &*c.conn; - let searcher = &c.searcher; + let searcher_actor = &c.actors.select("searcher-actor").unwrap(); let mut post = Post::from_id(c, &self.ap_url, None).map_err(|(_, e)| e)?; if !post.is_author(conn, actor.id)? { @@ -791,7 +792,8 @@ impl AsObject for PostUpdate { post.update_hashtags(conn, hashtags)?; } - post.update(conn, searcher)?; + post.update(conn)?; + searcher_actor.try_tell(UpdateDocument(post.clone()), None); Ok(()) } }