Repo integration #15

Merged
micialware merged 35 commits from repo-integration into master 2026-09-09 12:47:42 +03:00
3 changed files with 74 additions and 69 deletions
Showing only changes of commit 1509947cb0 - Show all commits

No files matched your search

+25 -24
View File
@@ -25,30 +25,31 @@ impl DeckData {
settings: &DeckSettings, settings: &DeckSettings,
state: AppState, state: AppState,
) -> Result<Self, NotificationData> { ) -> Result<Self, NotificationData> {
let state_for = state.clone(); todo!()
// let state_for = state.clone();
let stats = state (settings, &state.connection.read())?; //
let words = stats // let stats = state (settings, &state.connection.read())?;
.iter() // let words = stats
.map(|stat| { // .iter()
state // .map(|stat| {
.dictionary // state
.binary_search_by_key(&stat.word_id, |w| w.id) // .dictionary
.expect("No word found in dictionary") // .binary_search_by_key(&stat.word_id, |w| w.id)
}) // .expect("No word found in dictionary")
.map(|index| &state.dictionary[index]) // })
.cloned() // .map(|index| &state.dictionary[index])
.collect(); // .cloned()
// .collect();
Ok(Self { //
set: stats, // Ok(Self {
words, // set: stats,
current_word_index: None, // words,
state: state_for, // current_word_index: None,
order_module: Fsrs(FsrsModule::new()), // state: state_for,
open_mode: settings.open_mode, // order_module: Fsrs(FsrsModule::new()),
settings: settings.clone(), // open_mode: settings.open_mode,
}) // settings: settings.clone(),
// })
} }
pub fn next(&mut self) -> (WordData, CardState) { pub fn next(&mut self) -> (WordData, CardState) {
+42 -41
View File
@@ -111,47 +111,48 @@ impl DeckSettings {
ast.is_ok() ast.is_ok()
} }
pub fn get_word_list(&self, state: &AppState) -> Vec<usize> { pub fn get_word_list(&self, state: &AppState) -> Vec<usize> {
let time = Instant::now(); todo!()
let mut list = vec![]; // let time = Instant::now();
let engine = Engine::new(); // let mut list = vec![];
// let engine = Engine::new();
let ast = engine.compile(&self.filter); //
if let Ok(ast) = ast { // let ast = engine.compile(&self.filter);
let groups = state.word_groups.read(); // if let Ok(ast) = ast {
let query = state // let groups = state.word_groups.read();
.dictionary.read().query_par(| word: &WordData|{ // let query = state
let mut more = rhai::Map::new(); // .dictionary.read().query_par(| word: &WordData|{
for iced in &word.additional { // let mut more = rhai::Map::new();
more.insert(iced.0.clone().into(), iced.1.clone().into()); // for iced in &word.additional {
} // more.insert(iced.0.clone().into(), iced.1.clone().into());
let mut scope = Scope::new(); // }
let group_name = groups.get_ref(&mut groups.handle_by_id(word.group_id)).unwrap().name; // let mut scope = Scope::new();
// let group_name = groups.get_ref(&mut groups.handle_by_id(word.group_id)).unwrap().name;
scope //
.push_constant("id", word.id.0 as i64) // scope
.push_constant("key", word.key.clone()) // .push_constant("id", word.id.0 as i64)
.push_constant("value", word.value.clone()) // .push_constant("key", word.key.clone())
.push_constant("tags", word.tags.clone()) // .push_constant("value", word.value.clone())
.push_constant("more", more) // .push_constant("tags", word.tags.clone())
.push_constant( // .push_constant("more", more)
"group", // .push_constant(
group_name, // "group",
); // group_name,
// );
let result = engine.eval_ast_with_scope::<bool>(&mut scope, &ast); //
if let Ok(result) = result { // let result = engine.eval_ast_with_scope::<bool>(&mut scope, &ast);
return result; // if let Ok(result) = result {
} // return result;
false // }
}); // false
// });
//
info!("Collecting available words is {:?}", time.elapsed()); //
// info!("Collecting available words is {:?}", time.elapsed());
list //
} else { // list
list // } else {
} // list
// }
} }
pub fn require_speech(&self) -> bool { pub fn require_speech(&self) -> bool {
self.forward == "speech" || self.backward == "speech" self.forward == "speech" || self.backward == "speech"
+7 -4
View File
@@ -9,6 +9,7 @@ use rayon::iter::ParallelIterator;
use rusqlite::Connection; use rusqlite::Connection;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::ops::Deref; use std::ops::Deref;
use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
use crate::data_provider::sqlite::SqliteConnection; use crate::data_provider::sqlite::SqliteConnection;
@@ -94,13 +95,15 @@ where
} }
} }
} }
#[derive(Clone)]
pub struct Query<T, R, D> pub struct Query<T, R, D>
where where
R: Repository<T, D>, R: Repository<T, D>,
D: DbLayer<T>, D: DbLayer<T>,
{ {
cache: Vec<EntityHandle<T>>, cache: Vec<EntityHandle<T>>,
rule: Box<dyn Fn(&T) -> bool + Send + Sync>, rule: Arc<dyn Fn(&T) -> bool + Send + Sync>,
parallel: bool, parallel: bool,
_marker: PhantomData<(R, D)>, _marker: PhantomData<(R, D)>,
shift_stamp: usize, shift_stamp: usize,
@@ -140,7 +143,7 @@ impl<T: EntityData + Clone + Send + Sync, R: Repository<T, D>, D: DbLayer<T>> Qu
.cache .cache
.par_iter() .par_iter()
.enumerate() .enumerate()
.filter(|(_, entity)| (self.rule)(entity)) .filter(|(_, entity)| self.rule.as_ref()(entity))
.map(|(i, entity)| EntityHandle::new(entity.id(), i, true)) .map(|(i, entity)| EntityHandle::new(entity.id(), i, true))
.collect(); .collect();
} else { } else {
@@ -234,7 +237,7 @@ impl<T: std::clone::Clone + EntityData, D: DbLayer<T>> Deref for DataRepository<
impl<T: EntityData + Clone, D: DbLayer<T>> DataRepositoryInner<T, D> { impl<T: EntityData + Clone, D: DbLayer<T>> DataRepositoryInner<T, D> {
pub fn query_par( pub fn query_par(
&self, &self,
rule: Box<dyn Fn(&T) -> bool + Send + Sync>, rule: Arc<dyn Fn(&T) -> bool + Send + Sync>,
) -> Query<T, DataRepositoryInner<T, D>, D> ) -> Query<T, DataRepositoryInner<T, D>, D>
where where
T: Send + Sync, T: Send + Sync,
@@ -267,7 +270,7 @@ impl<T: EntityData + Clone, D: DbLayer<T>> DataRepositoryInner<T, D> {
pub fn query( pub fn query(
&self, &self,
rule: Box<dyn Fn(&T) -> bool + Send + Sync>, rule: Arc<dyn Fn(&T) -> bool + Send + Sync>,
) -> Query<T, DataRepositoryInner<T, D>, D> ) -> Query<T, DataRepositoryInner<T, D>, D>
where where
T: Send + Sync, T: Send + Sync,