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

Refactoring fetch_bookmark to avoid extra queries #1306

Merged
merged 1 commit into from
Jun 26, 2019
Merged

Refactoring fetch_bookmark to avoid extra queries #1306

merged 1 commit into from
Jun 26, 2019

Conversation

0x00A5
Copy link
Contributor

@0x00A5 0x00A5 commented Jun 17, 2019

fixes #806

@0x00A5
Copy link
Contributor Author

0x00A5 commented Jun 17, 2019

Hi @thomcc, it seems shasum -a 256 -c openssl-1.1.1a.tar.gz failed in the Rust benchmarks test. Could you help me rerun this test? It doesn't look like the failure is related to my changes. Thanks!

@thomcc
Copy link
Contributor

thomcc commented Jun 17, 2019

Retriggered, I agree it seems unrelated.

Just FYI, most of the team is traveling for a conference so review turnaround might be slightly slower this week.

@thomcc thomcc requested a review from linabutler June 18, 2019 17:53
Copy link
Member

@linabutler linabutler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lyuyuan92, thanks so much for the patch, and apologies for the delay in reviewing! This looks fantastic! The only blocking question I had is using the level that we get back from the query, instead of keeping track of it ourselves. I wouldn't mind having another look, so requesting changes, but this is in pretty good shape for merging soon! 🚀🚢

}
None => return Ok(None),
};

// Skip the rest and return if root is not a folder
match root {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Or-patterns in if-let are stabilized in Rust 1.33; you might be able to use if let BookmarkTreeNode::Bookmark(_) | BookmarkTreeNode::Separator(_) = root here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// Keep track of folders' guid of each level. Initialize the vector with two
// sets, which are for the root and its immediate children folders.
let mut node_vec: Vec<HashSet<SyncGuid>> = vec![HashSet::new(); 2];
let mut curr_depth: usize = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the query already selects the level, and we can access it via row.level. Do you think we can replace node_vec and curr_depth with a check like row.level > d + 1 in the loop below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I am a bit silly here...totally forgot about the level field. Done.

return Ok(if get_direct_children {
ChildInfo::Nodes(vec![])
fn set_child_guids_and_drop(parent: &mut PublicNode) {
if let Some(children) = parent.child_nodes.take() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You can make this a one-liner with a couple of maps, if you like. 😄

parent.child_guids = parent
        .child_nodes
        .take()
        .map(|children| children.into_iter().map(|child| child.guid).collect());

...And even inline that into fetch_bookmark, since it's pretty short. But I'm also totally fine with keeping it as a separate function, if you think it's more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The suggested code is much cleaner, thanks!

1. Allow a depth parameter to be passed into fetch_tree.
2. Refact fetch bookmark functions.
Copy link
Member

@linabutler linabutler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! 💯 Thanks again for doing this, let's land it!

@linabutler linabutler merged commit 7c2d3b3 into mozilla:master Jun 26, 2019
@0x00A5 0x00A5 deleted the fix_issue_806 branch June 26, 2019 00:03
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.

fetch_bookmark does more queries than we'd like when get_direct_children is true
3 participants