diff --git a/README.md b/README.md index 322e0a2..b7b3da7 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Heavily WIP. Doesn't work yet at all, but does read the stream of posts as they - [x] Keep subscription state to not lose messages - [x] Serve the feed - [ ] Publish the feed -- [ ] Handle deleting of posts +- [x] Handle deleting of posts ## Configuration diff --git a/src/processes/post_indexer.rs b/src/processes/post_indexer.rs index a06beba..4a7665c 100644 --- a/src/processes/post_indexer.rs +++ b/src/processes/post_indexer.rs @@ -82,8 +82,7 @@ impl CommitProcessor for PostIndexer { Operation::DeletePost { uri } => { info!("Received a post to delete: {uri}"); - // TODO: Delete posts from db - // self.database.delete_post(&self.db_connection_pool, &uri).await?; + self.database.delete_post(&uri).await?; } _ => continue, } diff --git a/src/services/database.rs b/src/services/database.rs index 30f4fb6..ccbd3e4 100644 --- a/src/services/database.rs +++ b/src/services/database.rs @@ -1,6 +1,8 @@ use anyhow::Result; use chrono::{DateTime, Utc}; -use scooby::postgres::{insert_into, select, update, Aliasable, Joinable, Orderable, Parameters}; +use scooby::postgres::{ + delete_from, insert_into, select, update, Aliasable, Joinable, Orderable, Parameters, +}; use sqlx::postgres::{PgPool, PgPoolOptions, PgRow}; use sqlx::query; use sqlx::Row; @@ -83,6 +85,20 @@ impl Database { .await?) } + pub async fn delete_post(&self, uri: &str) -> Result { + let mut params = Parameters::new(); + + Ok(query( + &delete_from("Post") + .where_(format!("uri = {}", params.next())) + .to_string(), + ) + .bind(uri) + .execute(&self.connection_pool) + .await + .map(|result| result.rows_affected() > 0)?) + } + pub async fn insert_profile_if_it_doesnt_exist(&self, did: &str) -> Result { let mut params = Parameters::new();