Faster new set initializing
This commit is contained in:
+13
-10
@@ -1,6 +1,5 @@
|
||||
use crate::data_provider::card_stats::{
|
||||
add_stat, delete_stat, load_stats_of_set, update_stat_score,
|
||||
};
|
||||
use crate::data_provider::card_stats::{add_stat_list, delete_stat, load_stats_of_set, update_stat_score};
|
||||
use crate::data_provider::history::{push_note, HistoryItem};
|
||||
use crate::repetitions::CardSetSettings;
|
||||
use crate::AppState;
|
||||
use chrono::{DateTime, Utc};
|
||||
@@ -13,7 +12,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::cmp::min;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use crate::data_provider::history::{push_note, HistoryItem};
|
||||
use std::time::Instant;
|
||||
|
||||
const MAX_HISTORY_LEN: usize = 20;
|
||||
const MAX_HISTORY_LEN_PART: f32 = 0.33;
|
||||
@@ -329,7 +328,7 @@ impl CardSet {
|
||||
let saved_ids = current_set.iter().map(|l| l.word_id).collect::<Vec<u32>>();
|
||||
let word_ids = last_list.iter().map(|l| l.id).collect::<Vec<u32>>();
|
||||
|
||||
last_list
|
||||
let new_stats: &mut Vec<CardStatistics> = &mut last_list
|
||||
.iter()
|
||||
.filter(|word| !saved_ids.contains(&word.id))
|
||||
.map(|word| CardStatistics {
|
||||
@@ -338,12 +337,16 @@ impl CardSet {
|
||||
last_open: Utc::now(),
|
||||
score: 1,
|
||||
set_id: settings.id.clone(),
|
||||
})
|
||||
.for_each(|mut new_statistic| {
|
||||
add_stat(&mut new_statistic, &state_locked.connection);
|
||||
current_set.push(new_statistic);
|
||||
});
|
||||
}).collect();
|
||||
|
||||
let time = Instant::now();
|
||||
|
||||
if !new_stats.is_empty() {
|
||||
add_stat_list(new_stats, &state_locked.connection);
|
||||
current_set.append(new_stats);
|
||||
}
|
||||
|
||||
println!("Added {} stats: {}", new_stats.len(), time.elapsed().as_millis());
|
||||
let mut index = 0;
|
||||
for stat in current_set.clone() {
|
||||
if !word_ids.contains(&stat.word_id) {
|
||||
|
||||
Reference in New Issue
Block a user