Final code cleanup

This commit is contained in:
2026-08-20 00:42:06 +03:00
parent ac1b516a88
commit 3661173bb0
3 changed files with 47 additions and 48 deletions
+45 -47
View File
@@ -1,9 +1,10 @@
use crate::AppState;
use crate::data_provider::card_stats::{delete_stat, load_stats_of_deck, update_stat_score};
use crate::data_provider::history::{HistoryItem, push_note};
use crate::data_provider::history::{push_note, HistoryItem};
use crate::AppState;
use chrono::{DateTime, Utc};
use rand::distr::Distribution;
use parking_lot::Mutex;
use rand::distr::weighted::WeightedIndex;
use rand::distr::Distribution;
use rand::prelude::SliceRandom;
use rand::rng;
use rand::rngs::ThreadRng;
@@ -11,15 +12,14 @@ use rayon::iter::IndexedParallelIterator;
use rayon::iter::IntoParallelRefIterator;
use rayon::iter::ParallelIterator;
use rhai::{Engine, Scope};
use rusqlite::ToSql;
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef};
use rusqlite::ToSql;
use std::cmp::PartialEq;
use std::collections::HashMap;
use std::fmt::{Display, Formatter};
use std::num::ParseIntError;
use std::str::FromStr;
use std::sync::Arc;
use parking_lot::Mutex;
use std::time::Instant;
const MAX_HISTORY_LEN: usize = 20;
@@ -668,49 +668,47 @@ impl DeckSettings {
let engine = Engine::new();
let ast = engine.compile(&self.filter);
if ast.is_err() {
return list;
if let Ok(ast) = ast {
let groups = &state.word_groups;
list = state
.dictionary
.par_iter()
.enumerate()
.filter(|(_, word)| {
let mut more = rhai::Map::new();
for iced in &word.additional {
more.insert(iced.0.clone().into(), iced.1.clone().into());
}
let mut scope = Scope::new();
scope
.push_constant("id", word.id.0)
.push_constant("key", word.key.clone())
.push_constant("value", word.value.clone())
.push_constant("tags", word.tags.clone())
.push_constant("more", more)
.push_constant(
"group",
groups
.iter()
.find(|g| g.id == word.group_id)
.cloned()
.unwrap()
.name,
);
let result = engine.eval_ast_with_scope::<bool>(&mut scope, &ast);
result.is_ok() && result.unwrap()
})
.map(|(index, _)| index)
.collect();
println!("Collecting available words is {:?}", time.elapsed());
list
} else {
list
}
let ast = ast.unwrap();
let groups = &state.word_groups;
list = state
.dictionary
.par_iter()
.enumerate()
.filter(|(_, word)| {
let mut more = rhai::Map::new();
for iced in &word.additional {
more.insert(iced.0.clone().into(), iced.1.clone().into());
}
let mut scope = Scope::new();
scope
.push_constant("id", word.id.0)
.push_constant("key", word.key.clone())
.push_constant("value", word.value.clone())
.push_constant("tags", word.tags.clone())
.push_constant("more", more)
.push_constant(
"group",
groups
.iter()
.find(|g| g.id == word.group_id)
.cloned()
.unwrap()
.name,
);
let result = engine.eval_ast_with_scope::<bool>(&mut scope, &ast);
result.is_ok() && result.unwrap()
})
.map(|(index, _)| index)
.collect();
println!("Collecting available words is {:?}", time.elapsed());
list
}
pub fn require_speech(&self) -> bool {
self.forward == "speech" || self.backward == "speech"
+1
View File
@@ -56,6 +56,7 @@ fn main() -> iced::Result {
.run()
}
#[allow(unused_mut)]
fn window_settings() -> window::Settings {
let mut settings = window::Settings {
position: Position::Centered,
+1 -1
View File
@@ -132,7 +132,7 @@ impl ScreenState {
Ok(v) => v,
};
let id: Id = history_file_name[4..history_file_name.len() - 12]
let id = history_file_name[4..history_file_name.len() - 12]
.parse::<Id>()
.unwrap();