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:
commit
a419ef5319
@ -28,6 +28,7 @@
|
||||
- Upsert posts and media instead of trying to insert and fail (#912)
|
||||
- Update post's ActivityPub id when published by update (#915)
|
||||
- Calculate media URI properly even when MEDIA_UPLOAD_DIRECTORY configured (#916)
|
||||
- Prevent duplicated posts in 'all' timeline (#917)
|
||||
|
||||
## [[0.6.0]] - 2020-12-29
|
||||
|
||||
|
@ -223,6 +223,9 @@ impl Timeline {
|
||||
}
|
||||
|
||||
pub fn add_post(&self, conn: &Connection, post: &Post) -> Result<()> {
|
||||
if self.includes_post(conn, post)? {
|
||||
return Ok(());
|
||||
}
|
||||
diesel::insert_into(timeline::table)
|
||||
.values(TimelineEntry {
|
||||
post_id: post.id,
|
||||
@ -236,6 +239,16 @@ impl Timeline {
|
||||
let query = TimelineQuery::parse(&self.query)?;
|
||||
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)]
|
||||
|
Loading…
Reference in New Issue
Block a user