Merge pull request 'Prevent duplicated posts in 'all' timeline' (#917) from dup-timeline into main

Reviewed-on: https://git.joinplu.me/Plume/Plume/pulls/917
This commit is contained in:
KitaitiMakoto 2021-03-29 15:31:52 +00:00
commit a419ef5319
2 changed files with 14 additions and 0 deletions

View file

@ -28,6 +28,7 @@
- Upsert posts and media instead of trying to insert and fail (#912) - Upsert posts and media instead of trying to insert and fail (#912)
- Update post's ActivityPub id when published by update (#915) - Update post's ActivityPub id when published by update (#915)
- Calculate media URI properly even when MEDIA_UPLOAD_DIRECTORY configured (#916) - Calculate media URI properly even when MEDIA_UPLOAD_DIRECTORY configured (#916)
- Prevent duplicated posts in 'all' timeline (#917)
## [[0.6.0]] - 2020-12-29 ## [[0.6.0]] - 2020-12-29

View file

@ -223,6 +223,9 @@ impl Timeline {
} }
pub fn add_post(&self, conn: &Connection, post: &Post) -> Result<()> { pub fn add_post(&self, conn: &Connection, post: &Post) -> Result<()> {
if self.includes_post(conn, post)? {
return Ok(());
}
diesel::insert_into(timeline::table) diesel::insert_into(timeline::table)
.values(TimelineEntry { .values(TimelineEntry {
post_id: post.id, post_id: post.id,
@ -236,6 +239,16 @@ impl Timeline {
let query = TimelineQuery::parse(&self.query)?; let query = TimelineQuery::parse(&self.query)?;
query.matches(conn, self, post, kind) query.matches(conn, self, post, kind)
} }
fn includes_post(&self, conn: &Connection, post: &Post) -> Result<bool> {
diesel::dsl::select(diesel::dsl::exists(
timeline::table
.filter(timeline::timeline_id.eq(self.id))
.filter(timeline::post_id.eq(post.id)),
))
.get_result(conn)
.map_err(Error::from)
}
} }
#[cfg(test)] #[cfg(test)]