diff --git a/benches/split_bench.rs b/benches/split_bench.rs deleted file mode 100644 index 3ecfd90..0000000 --- a/benches/split_bench.rs +++ /dev/null @@ -1,43 +0,0 @@ -use std::hint::black_box; -use criterion::{Criterion, criterion_group, criterion_main}; - -fn bench_split(c: &mut Criterion) { - let input = "data_1"; - - c.bench_function("split_with_comma", |b| { - b.iter(|| { - // black_box запрещает компилятору оптимизировать результат - black_box(split_with_coma(black_box(input))) - }) - }); -} - -fn bench_split_new(c: &mut Criterion) { - let input = "data_1"; - - c.bench_function("split_with_comma gpt", |b| { - b.iter(|| { - // black_box запрещает компилятору оптимизировать результат - black_box(split_with_coma(black_box(input))) - }) - }); -} - -pub fn split_with_coma(ts: &str) -> Vec { - ts.split(',') - .map(|ts| ts.to_lowercase().trim().to_string()) - .filter(|t| !t.is_empty()) - .collect::>() -} - -pub fn new_split_with_coma(ts: &str) -> Vec { - ts.split(',') - .map(|s| s.trim()) // 0 аллокаций, просто срез - .filter(|s| !s.is_empty()) // отбрасываем пустые до аллокации - .map(|s| s.to_lowercase()) // 1 аллокация на валидный токен - .collect() -} - -// Можно добавить несколько бенчмарков в группу -criterion_group!(benches, bench_split, bench_split_new); -criterion_main!(benches); diff --git a/src/data_provider/card_stats.rs b/src/data_provider/card_stats.rs index 068612e..abe4965 100644 --- a/src/data_provider/card_stats.rs +++ b/src/data_provider/card_stats.rs @@ -1,5 +1,5 @@ use crate::lang::{CardStatistics, DeckSettings}; -use rusqlite::Connection; +use rusqlite::{params, Connection}; use std::time::Instant; pub fn load_stats_of_deck(set: &DeckSettings, connection: &Connection) -> Vec { @@ -26,67 +26,41 @@ pub fn load_stats_of_deck(set: &DeckSettings, connection: &Connection) -> Vec>() - .join(", "); - let query = format!( - "INSERT INTO card_stats (word_id, set_id, score, last_opened) VALUES {}", - inserting - ); - let count = connection.execute(query.as_str(), ()); - - if count.is_err() { - return; + ]) + .unwrap(); + } } - let last_index: u32 = connection - .query_one( - "SELECT seq from sqlite_sequence WHERE name == ?1", - ("card_stats".to_string(),), - |row| row.get(0), - ) - .unwrap(); + let last_index: u32 = tx.last_insert_rowid() as u32; + tx.commit().unwrap(); - let start_index = last_index - (stat.len() as u32) + 1; + let start_index = last_index - (count as u32) + 1; for (index, id) in (start_index..=last_index).enumerate() { - stat[index].id = id.into(); + stats[index].id = id.into(); } - println!("Added {} cards for {:?}", stat.len(), time.elapsed()); + println!("Added {} cards for {:?}", stats.len(), time.elapsed()); } -// pub fn add_stat(stat: &mut CardStatistics, connection: &Connection) { -// let time = Instant::now(); -// let index = connection -// .query_row( -// "INSERT INTO card_stats (word_id, set_id, score, last_opened) VALUES (?1, ?2, ?3, ?4) RETURNING id", -// ( -// &stat.word_id, -// &stat.set_id, -// &stat.score, -// &stat.last_open.timestamp(), -// ), -// |row| row.get(0) -// ) -// .unwrap_or_else(|e| {println!("{}", e); 0}); -// -// stat.id = index; -// println!("Added stat: {}", time.elapsed().as_millis()); -// } - pub fn update_stat_score(stat: &CardStatistics, connection: &Connection) { let time = Instant::now(); diff --git a/src/data_provider/words.rs b/src/data_provider/words.rs index e20eff5..bb52107 100644 --- a/src/data_provider/words.rs +++ b/src/data_provider/words.rs @@ -46,15 +46,9 @@ pub fn add_words(words: &mut [WordData], connection: &mut Connection) { } } + let last_index: u32 = tx.last_insert_rowid() as u32; tx.commit().unwrap(); - let last_index: u32 = connection - .query_one( - "SELECT seq from sqlite_sequence WHERE name == ?1", - ("words".to_string(),), - |row| row.get(0), - ) - .unwrap(); let start_index = last_index - (count as u32) + 1; diff --git a/src/helpers.rs b/src/helpers.rs deleted file mode 100644 index 8b13789..0000000 --- a/src/helpers.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/lang.rs b/src/lang.rs index e0de7c1..9d33c7f 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -452,7 +452,7 @@ impl DeckData { HistoryItem { timestamp: Utc::now(), word_id: word.word_id.into(), - mode: WordOpenMode::Easy, + mode: status, before: old_score, after: new_score, }, diff --git a/src/main.rs b/src/main.rs index 297eafd..67bc533 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ mod data_provider; mod dictionary; mod dictionary_test; -pub mod helpers; mod history; pub mod import; mod lang; diff --git a/src/quiz.rs b/src/quiz.rs index 423a629..70af76c 100644 --- a/src/quiz.rs +++ b/src/quiz.rs @@ -54,7 +54,7 @@ impl NavigatedPage for QuizState { self.update_showed() } } - Back => todo!(), + Back => {}, } Task::none() } diff --git a/src/repetitions.rs b/src/repetitions.rs index d86126d..0e0c529 100644 --- a/src/repetitions.rs +++ b/src/repetitions.rs @@ -47,7 +47,7 @@ impl NavigatedPage for RepetitionsState { let selected_set = self.selected_deck_mut().unwrap(); if selected_set.append_mode == AppendMode::Full { - Self::append_all_words(&clone.lock().unwrap(), selected_set); + Self::append_all_words(&mut clone.lock().unwrap(), selected_set); selected_set.existing_words_indices = selected_set.available_words_indices.clone(); } else { if selected_set @@ -220,8 +220,8 @@ impl NavigatedPage for RepetitionsState { } let deck = self.selected_deck().unwrap(); - let state = self.state.lock().unwrap(); - Self::append_words(&state, &deck.general_settings, adding.into_iter()); + let mut state = self.state.lock().unwrap(); + Self::append_words(&mut state, &deck.general_settings, adding.into_iter()); } } Task::none() @@ -565,7 +565,7 @@ impl RepetitionsState { } impl RepetitionsState { - fn append_all_words(state: &AppState, deck: &DeckViewData) { + fn append_all_words(state: &mut AppState, deck: &DeckViewData) { let existing = deck.existing_words_indices.as_ref().unwrap(); let mut created_set = HashSet::with_capacity(existing.len()); existing.iter().for_each(|c| { @@ -580,7 +580,7 @@ impl RepetitionsState { .cloned(); Self::append_words(state, deck, required); } - fn append_words(state: &AppState, deck: &DeckSettings, indices: impl Iterator) { + fn append_words(state: &mut AppState, deck: &DeckSettings, indices: impl Iterator) { let words = &state.dictionary; let stats = &mut indices .map(|i| { @@ -596,7 +596,7 @@ impl RepetitionsState { .collect::>(); if !stats.is_empty() { - add_stat_list(stats, &state.connection); + add_stat_list(stats, &mut state.connection); } } diff --git a/src/writing.rs b/src/writing.rs index d5a4228..4f3a418 100644 --- a/src/writing.rs +++ b/src/writing.rs @@ -30,7 +30,7 @@ impl NavigatedPage for WritingState { fn navigated(&mut self) {} fn update(&mut self, message: WritingMessage) -> Task { match message { - WritingMessage::Back => todo!(), + WritingMessage::Back => {}, WritingMessage::Next => self.next(), WritingMessage::SwitchShowMode(b) => self.show_all = b, }