-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add post_replies source in user stream #239
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks good. There is a few things we can improve.
This PR still needs at least 1 more test and it would be very nice if we also add a benchmark for this new stream of users.
src/models/user/stream.rs
Outdated
let post_id = post_id.unwrap(); | ||
let author_id = author_id.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs proper handling instead of unwrap()
let post_id = post_id.ok_or_else(|| {
anyhow!("Post ID should be provided for user streams with source 'post_replies'")
})?;
let author_id = author_id.ok_or_else(|| {
anyhow!("Author ID should be provided for user streams with source 'post_replies'")
})?;
src/models/user/stream.rs
Outdated
let unique_user_ids: HashSet<String> = replies | ||
.map(|replies| { | ||
replies | ||
.into_iter() | ||
.map(|reply| reply.0.split(":").next().unwrap().to_string()) | ||
.collect::<Vec<String>>() | ||
}) | ||
.into_iter() | ||
.flatten() | ||
.collect(); | ||
Some(unique_user_ids.into_iter().collect()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid unwrap()
Untested, maybe something like.
let unique_user_ids: HashSet<String> = replies
.map(|replies_batch| {
replies_batch
.into_iter()
.filter_map(|(raw_id, _some_other_data)| {
// Split on ":" and take the first piece; avoid `unwrap()`
raw_id.split(':').next().map(ToString::to_string)
})
.collect::<Vec<String>>()
})
.flatten()
.collect();
src/models/user/stream.rs
Outdated
UserStreamSource::PostReplies => { | ||
let post_id = post_id.unwrap(); | ||
let author_id = author_id.unwrap(); | ||
let key_parts = [ | ||
&POST_REPLIES_PER_POST_KEY_PARTS[..], | ||
&[author_id.as_str(), post_id.as_str()], | ||
] | ||
.concat(); | ||
let replies = PostStream::try_from_index_sorted_set( | ||
&key_parts, | ||
None, | ||
None, | ||
None, | ||
None, | ||
SortOrder::Descending, | ||
None, | ||
) | ||
.await?; | ||
let unique_user_ids: HashSet<String> = replies | ||
.map(|replies| { | ||
replies | ||
.into_iter() | ||
.map(|reply| reply.0.split(":").next().unwrap().to_string()) | ||
.collect::<Vec<String>>() | ||
}) | ||
.into_iter() | ||
.flatten() | ||
.collect(); | ||
Some(unique_user_ids.into_iter().collect()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too much logic inside of this arm of the match statement.
We should do the same as for the UserStreamSource::Recommended
arm. Move the logic to a new get_post_replies_ids(post_id: &str, author_id: &str) -> Result<Option<Vec<String>>, DynError>
function.
Please use the keyword |
47d5dcb
to
17d5240
Compare
Is this PR ready for review? |
This PR fixes #228
Pre-submission Checklist
cargo test
.cargo bench