refactor
This commit is contained in:
parent
c54269bef5
commit
122e47303b
42
src/main.rs
42
src/main.rs
@ -246,12 +246,12 @@ impl From<&SourceQuestionsBatch> for BatchInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<Vec<Question>> for SourceQuestionsBatch {
|
impl From<SourceQuestionsBatch> for Vec<Question> {
|
||||||
fn into(self) -> Vec<Question> {
|
fn from(src: SourceQuestionsBatch) -> Self {
|
||||||
let mut result = Vec::<Question>::with_capacity(self.questions.len());
|
let mut result = Vec::<Question>::with_capacity(src.questions.len());
|
||||||
self.questions.iter().for_each(|item| {
|
src.questions.iter().for_each(|item| {
|
||||||
let mut question: Question = item.clone().into();
|
let mut question: Question = item.clone().into();
|
||||||
question.batch_info = BatchInfo::from(&self);
|
question.batch_info = BatchInfo::from(&src);
|
||||||
result.push(question);
|
result.push(question);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ pub fn measure<F: FnOnce()>(func: F) -> f64 {
|
|||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
func();
|
func();
|
||||||
let elapsed = start.elapsed();
|
let elapsed = start.elapsed();
|
||||||
(elapsed.as_secs() as f64) + (elapsed.subsec_nanos() as f64 / 1000_000_000.0)
|
(elapsed.as_secs() as f64) + (elapsed.subsec_nanos() as f64 / 1_000_000_000.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn measure_and_print<F: FnOnce()>(func: F) {
|
pub fn measure_and_print<F: FnOnce()>(func: F) {
|
||||||
@ -308,19 +308,18 @@ fn writer_v4() {
|
|||||||
(String::from(name_str), data)
|
(String::from(name_str), data)
|
||||||
})
|
})
|
||||||
.filter(|(_, data)| data.is_ok())
|
.filter(|(_, data)| data.is_ok())
|
||||||
.map(|(filename, data)| {
|
.flat_map(|(filename, data)| {
|
||||||
let mut data = data.unwrap();
|
let mut data = data.unwrap();
|
||||||
data.filename = filename.clone();
|
data.filename = filename;
|
||||||
let questions: Vec<Question> = data.into();
|
let questions: Vec<Question> = data.into();
|
||||||
questions
|
questions
|
||||||
})
|
})
|
||||||
.flatten()
|
|
||||||
.for_each(|question| {
|
.for_each(|question| {
|
||||||
let result = collection.insert(&question);
|
let result = collection.insert(&question);
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
println!(
|
println!(
|
||||||
"Error: {:?} \n\
|
"Error: {:?} \n\
|
||||||
On: {:?}",
|
On: {:?}",
|
||||||
result, question
|
result, question
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -329,6 +328,11 @@ fn writer_v4() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
println!("inserted {}", count);
|
println!("inserted {}", count);
|
||||||
|
storage.sync(true).unwrap();
|
||||||
|
print!("stats: ");
|
||||||
|
let stats = storage.stat().unwrap();
|
||||||
|
println!("{:?}", stats);
|
||||||
|
drop(storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_question(q: Question) {
|
fn print_question(q: Question) {
|
||||||
@ -347,13 +351,7 @@ fn reader_v1() -> Option<Question> {
|
|||||||
let data = data.unwrap();
|
let data = data.unwrap();
|
||||||
let questions: Vec<Question> = data.into();
|
let questions: Vec<Question> = data.into();
|
||||||
|
|
||||||
let ret = questions.iter().choose(&mut rng);
|
questions.into_iter().choose(&mut rng)
|
||||||
|
|
||||||
if let Some(question) = ret {
|
|
||||||
Some(question.clone())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compact_db() {
|
fn compact_db() {
|
||||||
@ -367,13 +365,11 @@ fn compact_db() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let storage = Storage::new("db", options).unwrap();
|
let storage = Storage::new("db", options).unwrap();
|
||||||
//let collection = storage.collection("questions").unwrap();
|
|
||||||
|
|
||||||
//query!(index for collection
|
storage.sync(true).unwrap();
|
||||||
// num int,
|
let stats = storage.stat().unwrap();
|
||||||
// batch_info.filename str,
|
println!("{:?}", stats);
|
||||||
//)
|
drop(storage);
|
||||||
//.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reader_v4() -> Option<Question> {
|
fn reader_v4() -> Option<Question> {
|
||||||
|
Loading…
Reference in New Issue
Block a user