summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-01-06 17:48:05 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-01-06 18:26:28 +0100
commitbf21ffb6d8cca0947f92184d2afc816eeaef5efd (patch)
treed0bfd950d5064c4f607b067515a407f7dcd3d7a8
parentbd8efaac79d6dbed185dfbf3369a615bac5edc91 (diff)
Reimplement fill_arena_with() using threads for accumulation
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/domain/libimagmail/src/mailtree.rs48
1 files changed, 29 insertions, 19 deletions
diff --git a/lib/domain/libimagmail/src/mailtree.rs b/lib/domain/libimagmail/src/mailtree.rs
index e2f9c288..bec50f9e 100644
--- a/lib/domain/libimagmail/src/mailtree.rs
+++ b/lib/domain/libimagmail/src/mailtree.rs
@@ -53,25 +53,35 @@ impl Mailtree {
fn fill_arena_with<'a>(arena: &mut Arena<String>, store: &'a MailStoreWithConnection<'a>, root: LoadedMail) -> Result<NodeId> {
trace!("Filling arena starting at: {}", root.get_id());
- let root_node = arena.new_node(root.get_id().clone());
-
- root.replies(store.connection())?
- .into_iter()
- .map(|id| {
- trace!("Processing {} reply: {}", root.get_id(), id);
- let mail = store.get_mail_by_id(&id)?
- .ok_or_else(|| format_err!("Cannot find mail for id {}", id))?;
-
- let reply = mail
- .load(store.connection())?
- .ok_or_else(|| format_err!("Tried to load unavailable mail: {}", mail.get_location()))?;
-
- let new_node_id = arena.new_node(id);
- root_node.append(new_node_id, arena);
- fill_arena_with(arena, store, reply)
- })
- .collect::<Result<Vec<_>>>()
- .map(|_| root_node)
+ let root_id = root.get_id().clone();
+ let root_node = arena.new_node(root_id);
+
+ store.connection().execute(|db| {
+ let query = db.create_query(&format!("thread:{}", root.get_thread_id()))?;
+ let r = query.search_threads()?
+ .map(|thread| {
+ thread.messages()
+ .map(|msg| {
+ let id = msg.id();
+ trace!("Processing {} reply: {}", root.get_id(), id);
+ let mail = store.get_mail_by_id(&id)?
+ .ok_or_else(|| format_err!("Cannot find mail for id {}", id))?;
+
+ let reply = mail
+ .load(store.connection())?
+ .ok_or_else(|| format_err!("Tried to load unavailable mail: {}", mail.get_location()))?;
+
+ let new_node_id = arena.new_node(id.into_owned());
+ root_node.append(new_node_id, arena);
+ fill_arena_with(arena, store, reply).map(|_| ())
+ })
+ .collect::<Result<Vec<_>>>()
+ })
+ .collect::<Result<Vec<_>>>()
+ .map(|_| root_node);
+
+ r
+ })
}
/// A type for traversing the Mailtree