sidebar: compute mailbox tree only for subscribed mailboxes

jmap-eventsource
Manos Pitsidianakis 2020-09-18 18:20:59 +03:00
parent 05e4dbcd5a
commit 8eb78ae01b
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 24 additions and 4 deletions

View File

@ -2157,10 +2157,24 @@ fn build_mailboxes_order(
}
drop(stack);
for node in tree.iter_mut() {
fn rec(node: &mut MailboxNode, depth: usize, mut indentation: u32, has_sibling: bool) {
fn rec(
node: &mut MailboxNode,
mailbox_entries: &IndexMap<MailboxHash, MailboxEntry>,
depth: usize,
mut indentation: u32,
has_sibling: bool,
) {
node.indentation = indentation;
node.has_sibling = has_sibling;
let mut iter = (0..node.children.len()).peekable();
let mut iter = (0..node.children.len())
.filter(|i| {
mailbox_entries[&node.children[*i].hash]
.ref_mailbox
.is_subscribed()
})
.collect::<SmallVec<[_; 8]>>()
.into_iter()
.peekable();
if has_sibling {
indentation <<= 1;
indentation |= 1;
@ -2169,10 +2183,16 @@ fn build_mailboxes_order(
}
while let Some(i) = iter.next() {
let c = &mut node.children[i];
rec(c, depth + 1, indentation, iter.peek() != None);
rec(
c,
mailbox_entries,
depth + 1,
indentation,
iter.peek() != None,
);
}
};
rec(node, 0, 1, false);
rec(node, &mailbox_entries, 0, 1, false);
}
}