fn assemble_posts(
            post_and_votes: (Post, VoteCounts),
            posts_and_votes: &mut Vec<(Post, VoteCounts)>,
            users: &HashMap<Uuid, User>,
        ) -> PostData {
            let children: Vec<(Post, VoteCounts)> = posts_and_votes
                .drain_filter(|child_post_and_votes: &mut (Post, VoteCounts)| {
                    let child_post: &Post = &child_post_and_votes.0;
                    if let Some(parent_uuid) = child_post.parent_uuid {
                        parent_uuid == post_and_votes.0.uuid
                    } else {
                        false
                    }
                })
                .collect();

            // Recurse
            let children: Vec<PostData> = children
                .into_iter()
                .map(|child_post: (Post, VoteCounts)| assemble_posts(child_post, posts_and_votes, users))
                .collect();

            let user: User = users
                .get(&post_and_votes.0.author_uuid)
                .cloned()
                .expect("The user at the uuid should exist");

            let (post, votes) = post_and_votes;

            PostData {
                post,
                user,
                votes,
                children,
            }
        }
/// Recursive function to assemble posts out of the list of post data.
/// It has a time complexity of O: n * log_n, but that is still better than talking to the database,
/// as the constant time is too great there.
Recursive function to assemble posts out of the list of post data.
It has a time complexity of O: n * log_n, but that is still better than talking to the database,
as the constant time is too great there.
Recursive function to assemble posts out of the list of post data . It has a time complexity of O : n * log_n but that is still better than talking to the database as the constant time is too great there .
fn assemble_posts(
            post_and_votes: (Post, VoteCounts),
            posts_and_votes: &mut Vec<(Post, VoteCounts)>,
            users: &HashMap<Uuid, User>,
        ) -> PostData {
            let children: Vec<(Post, VoteCounts)> = posts_and_votes
                .drain_filter(|child_post_and_votes: &mut (Post, VoteCounts)| {
                    let child_post: &Post = &child_post_and_votes.0;
                    if let Some(parent_uuid) = child_post.parent_uuid {
                        parent_uuid == post_and_votes.0.uuid
                    } else {
                        false
                    }
                })
                .collect();
            // Recurse
            let children: Vec<PostData> = children
                .into_iter()
                .map(|child_post: (Post, VoteCounts)| assemble_posts(child_post, posts_and_votes, users))
                .collect();
            let user: User = users
                .get(&post_and_votes.0.author_uuid)
                .cloned()
                .expect("The user at the uuid should exist");
            let (post, votes) = post_and_votes;
            PostData {
                post,
                user,
                votes,
                children,
            }
        }
fn assemble_posts ( post_and_votes : ( Post , VoteCounts ) , posts_and_votes : & mut Vec < ( Post , VoteCounts ) > , users : & HashMap < Uuid , User > , ) -> PostData { let children : Vec < ( Post , VoteCounts ) > = posts_and_votes . drain_filter ( | child_post_and_votes : & mut ( Post , VoteCounts ) | { let child_post : & Post = & child_post_and_votes . 0 ; if let Some ( parent_uuid ) = child_post . parent_uuid { parent_uuid == post_and_votes . 0 . uuid } else { false } } ) . collect ( ) ; // Recurse let children : Vec < PostData > = children . into_iter ( ) . map ( | child_post : ( Post , VoteCounts ) | assemble_posts ( child_post , posts_and_votes , users ) ) . collect ( ) ; let user : User = users . get ( & post_and_votes . 0 . author_uuid ) . cloned ( ) . expect ( " " ) ; let ( post , votes ) = post_and_votes ; PostData { post , user , votes , children , } }
Recursive function to assemble posts out of the list of post data.
Recursive function to assemble posts out of the list of post data .
post_and_votes
(Post, VoteCounts)
posts_and_votes
&mut Vec<(Post, VoteCounts)>
users
&HashMap<Uuid, User>
post_and_votes
(Post, VoteCounts)
posts_and_votes
&mut Vec<(Post, VoteCounts)>
users
&HashMap<Uuid, User>