Skip to content
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

Add post_replies source in user stream #239

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

amirRamirfatahi
Copy link
Collaborator

This PR solves #228

Pre-submission Checklist

For tests to work you need a working neo4j and redis instance with the example dataset in docker/db-graph

  • Testing: Implement and pass new tests for the new features/fixes, cargo test.
  • Performance: Ensure new code has relevant performance benchmarks, cargo bench

@amirRamirfatahi amirRamirfatahi changed the title Add post_replies Add post_replies source in user stream Dec 5, 2024
@tipogi tipogi linked an issue Dec 6, 2024 that may be closed by this pull request
Copy link
Collaborator

@SHAcollision SHAcollision left a 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.

Comment on lines +271 to +272
let post_id = post_id.unwrap();
let author_id = author_id.unwrap();
Copy link
Collaborator

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'")
        })?;

Comment on lines +288 to +298
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())
Copy link
Collaborator

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();

Comment on lines +270 to +299
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())
}
Copy link
Collaborator

@SHAcollision SHAcollision Jan 2, 2025

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.

@SHAcollision
Copy link
Collaborator

SHAcollision commented Jan 2, 2025

This PR solves #228

Please use the keyword Fixes , e.g., This PR fixes #228 to automatically link this PR to the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat (service): user stream of reply participants
2 participants