Skip to content

Commit

Permalink
fix: missing filtering on personal feed
Browse files Browse the repository at this point in the history
  • Loading branch information
X committed Apr 19, 2024
1 parent 26f2d15 commit 7d7de4b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
18 changes: 9 additions & 9 deletions src/backend/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4208,7 +4208,7 @@ pub(crate) mod tests {
assert!(state
.user(&user_id.to_string())
.unwrap()
.personal_feed(state, 0, 0)
.personal_feed(state, 0)
.next()
.is_none());

Expand All @@ -4221,7 +4221,7 @@ pub(crate) mod tests {
.users
.get(&user_id)
.unwrap()
.personal_feed(state, 0, 0)
.personal_feed(state, 0)
.map(|post| post.id)
.collect::<Vec<_>>();
assert_eq!(feed.len(), 1);
Expand All @@ -4238,7 +4238,7 @@ pub(crate) mod tests {
.users
.get(&user_id)
.unwrap()
.personal_feed(state, 0, 0)
.personal_feed(state, 0)
.map(|post| post.id)
.collect::<Vec<_>>();
assert_eq!(feed.len(), 1);
Expand All @@ -4264,7 +4264,7 @@ pub(crate) mod tests {
.users
.get(&user_id)
.unwrap()
.personal_feed(state, 0, 0)
.personal_feed(state, 0)
.map(|post| post.id)
.collect::<Vec<_>>();
assert_eq!(feed.len(), 2);
Expand All @@ -4291,7 +4291,7 @@ pub(crate) mod tests {
.users
.get(&user_id)
.unwrap()
.personal_feed(state, 0, 0)
.personal_feed(state, 0)
.map(|post| post.id)
.collect::<Vec<_>>();
assert_eq!(feed.len(), 2);
Expand All @@ -4307,7 +4307,7 @@ pub(crate) mod tests {
.users
.get(&user_id)
.unwrap()
.personal_feed(state, 0, 0)
.personal_feed(state, 0)
.map(|post| post.id)
.collect::<Vec<_>>();
assert_eq!(feed.len(), 3);
Expand All @@ -4322,7 +4322,7 @@ pub(crate) mod tests {
.users
.get(&user_id)
.unwrap()
.personal_feed(state, 0, 0)
.personal_feed(state, 0)
.map(|post| post.id)
.collect::<Vec<_>>();
assert_eq!(feed.len(), 2);
Expand All @@ -4336,7 +4336,7 @@ pub(crate) mod tests {
.users
.get(&user_id)
.unwrap()
.personal_feed(state, 0, 0)
.personal_feed(state, 0)
.map(|post| post.id)
.collect::<Vec<_>>();
assert!(feed.contains(&post_id));
Expand All @@ -4347,7 +4347,7 @@ pub(crate) mod tests {
.users
.get(&user_id)
.unwrap()
.personal_feed(state, 0, 0)
.personal_feed(state, 0)
.map(|post| post.id)
.collect::<Vec<_>>();
assert!(!feed.contains(&post_id));
Expand Down
10 changes: 4 additions & 6 deletions src/backend/env/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ impl User {
pub fn personal_feed<'a>(
&'a self,
state: &'a State,
page: usize,
offset: PostId,
) -> Box<dyn Iterator<Item = &'a Post> + 'a> {
let mut iterators: Vec<Box<dyn Iterator<Item = &'a Post> + 'a>> = self
Expand All @@ -336,8 +335,8 @@ impl User {
}

Box::new(
IteratorMerger::new(MergeStrategy::Or, iterators.into_iter().collect())
.filter(move |post| {
IteratorMerger::new(MergeStrategy::Or, iterators.into_iter().collect()).filter(
move |post| {
self.followees.contains(&post.user)
|| !post.matches_filters(&self.filters)
&& post
Expand All @@ -347,9 +346,8 @@ impl User {
self.show_posts_in_realms || self.realms.contains(realm_id)
})
.unwrap_or(true)
})
.skip(page * CONFIG.feed_page_size)
.take(CONFIG.feed_page_size),
},
),
)
}

Expand Down
5 changes: 4 additions & 1 deletion src/backend/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,10 @@ fn personal_feed() {
reply(match state.principal_to_user(caller()) {
None => Default::default(),
Some(user) => user
.personal_feed(state, page, offset)
.personal_feed(state, offset)
.filter(|post| personal_filter(state, Some(user), post))
.skip(page * CONFIG.feed_page_size)
.take(CONFIG.feed_page_size)
.map(|post| post.with_meta(state))
.collect::<Vec<_>>(),
})
Expand Down

0 comments on commit 7d7de4b

Please sign in to comment.