diff --git a/src/algos.rs b/src/algos.rs index 9fb4ebf..a1d6902 100644 --- a/src/algos.rs +++ b/src/algos.rs @@ -12,7 +12,12 @@ pub use self::nederlandskie::Nederlandskie; #[async_trait] pub trait Algo { - fn should_index_post(&self, author_did: &str, languages: &HashSet, text: &str) -> bool; + async fn should_index_post( + &self, + author_did: &str, + languages: &HashSet, + text: &str, + ) -> Result; async fn fetch_posts( &self, diff --git a/src/algos/nederlandskie.rs b/src/algos/nederlandskie.rs index 700fa75..6004333 100644 --- a/src/algos/nederlandskie.rs +++ b/src/algos/nederlandskie.rs @@ -24,13 +24,13 @@ impl Nederlandskie { /// An algorithm that serves posts written in Russian by people living in Netherlands #[async_trait] impl Algo for Nederlandskie { - fn should_index_post( + async fn should_index_post( &self, _author_did: &str, _languages: &HashSet, text: &str, - ) -> bool { - self.language_detector.detect_language_of(text) == Some(Russian) + ) -> Result { + Ok(self.language_detector.detect_language_of(text) == Some(Russian)) } async fn fetch_posts( diff --git a/src/processes/post_indexer.rs b/src/processes/post_indexer.rs index d6249e7..55da4d0 100644 --- a/src/processes/post_indexer.rs +++ b/src/processes/post_indexer.rs @@ -65,17 +65,18 @@ impl OperationProcessor for PostIndexer { languages, text, } => { - if self - .algos - .iter_all() - .any(|a| a.should_index_post(author_did, languages, text)) - { - info!("Received insertable post from {author_did}: {text}"); + for algo in self.algos.iter_all() { + if algo.should_index_post(author_did, languages, text).await? { + info!("Received insertable post from {author_did}: {text}"); - self.database - .insert_profile_if_it_doesnt_exist(&author_did) - .await?; - self.database.insert_post(&author_did, &cid, &uri).await?; + self.database + .insert_profile_if_it_doesnt_exist(&author_did) + .await?; + + self.database.insert_post(&author_did, &cid, &uri).await?; + + break; + } } } Operation::DeletePost { uri } => {