From 5ed8c12f9103bc0748792e68d06b664969466cb3 Mon Sep 17 00:00:00 2001
From: Dmitry <b4tm4n@mail.ru>
Date: Mon, 10 Oct 2022 16:15:16 +0300
Subject: [PATCH] use collection.load(rx) for writer task

---
 src/main.rs | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index c927639..7e058e6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -102,13 +102,9 @@ fn db_writer_task(rx: mpsc::Receiver<Question>) {
     let storage = Storage::new(DB_DIR, options).unwrap();
     let collection = storage.collection("questions").unwrap();
 
-    let mut count: usize = 0;
-    rx.into_iter().for_each(|question| {
-        collection.insert(question).expect("insert question");
-        count += 1;
-    });
+    let count = collection.load(rx).expect("load");
 
-    println!("inserted {count}");
+    println!("loaded {count}");
 
     println!("syncing to disk...");
     storage.sync(true).unwrap();