Delete posts from the database when they are deleted from bluesky
This commit is contained in:
parent
dd33333649
commit
658996d5d5
|
@ -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] Keep subscription state to not lose messages
|
||||||
- [x] Serve the feed
|
- [x] Serve the feed
|
||||||
- [ ] Publish the feed
|
- [ ] Publish the feed
|
||||||
- [ ] Handle deleting of posts
|
- [x] Handle deleting of posts
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
|
|
|
@ -82,8 +82,7 @@ impl CommitProcessor for PostIndexer {
|
||||||
Operation::DeletePost { uri } => {
|
Operation::DeletePost { uri } => {
|
||||||
info!("Received a post to delete: {uri}");
|
info!("Received a post to delete: {uri}");
|
||||||
|
|
||||||
// TODO: Delete posts from db
|
self.database.delete_post(&uri).await?;
|
||||||
// self.database.delete_post(&self.db_connection_pool, &uri).await?;
|
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use chrono::{DateTime, Utc};
|
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::postgres::{PgPool, PgPoolOptions, PgRow};
|
||||||
use sqlx::query;
|
use sqlx::query;
|
||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
|
@ -83,6 +85,20 @@ impl Database {
|
||||||
.await?)
|
.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn delete_post(&self, uri: &str) -> Result<bool> {
|
||||||
|
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<bool> {
|
pub async fn insert_profile_if_it_doesnt_exist(&self, did: &str) -> Result<bool> {
|
||||||
let mut params = Parameters::new();
|
let mut params = Parameters::new();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue