Temporal todo
This commit is contained in:
1 parent
55bdc5a7ad
commit
1509947cb0
3 files changed
+74
-69
No files matched your search
+25
-24
@@ -25,30 +25,31 @@ impl DeckData {
|
||||
settings: &DeckSettings,
|
||||
state: AppState,
|
||||
) -> Result<Self, NotificationData> {
|
||||
let state_for = state.clone();
|
||||
|
||||
let stats = state (settings, &state.connection.read())?;
|
||||
let words = stats
|
||||
.iter()
|
||||
.map(|stat| {
|
||||
state
|
||||
.dictionary
|
||||
.binary_search_by_key(&stat.word_id, |w| w.id)
|
||||
.expect("No word found in dictionary")
|
||||
})
|
||||
.map(|index| &state.dictionary[index])
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
Ok(Self {
|
||||
set: stats,
|
||||
words,
|
||||
current_word_index: None,
|
||||
state: state_for,
|
||||
order_module: Fsrs(FsrsModule::new()),
|
||||
open_mode: settings.open_mode,
|
||||
settings: settings.clone(),
|
||||
})
|
||||
todo!()
|
||||
// let state_for = state.clone();
|
||||
//
|
||||
// let stats = state (settings, &state.connection.read())?;
|
||||
// let words = stats
|
||||
// .iter()
|
||||
// .map(|stat| {
|
||||
// state
|
||||
// .dictionary
|
||||
// .binary_search_by_key(&stat.word_id, |w| w.id)
|
||||
// .expect("No word found in dictionary")
|
||||
// })
|
||||
// .map(|index| &state.dictionary[index])
|
||||
// .cloned()
|
||||
// .collect();
|
||||
//
|
||||
// Ok(Self {
|
||||
// set: stats,
|
||||
// words,
|
||||
// current_word_index: None,
|
||||
// state: state_for,
|
||||
// order_module: Fsrs(FsrsModule::new()),
|
||||
// open_mode: settings.open_mode,
|
||||
// settings: settings.clone(),
|
||||
// })
|
||||
}
|
||||
|
||||
pub fn next(&mut self) -> (WordData, CardState) {
|
||||
|
||||
+42
-41
@@ -111,47 +111,48 @@ impl DeckSettings {
|
||||
ast.is_ok()
|
||||
}
|
||||
pub fn get_word_list(&self, state: &AppState) -> Vec<usize> {
|
||||
let time = Instant::now();
|
||||
let mut list = vec![];
|
||||
let engine = Engine::new();
|
||||
|
||||
let ast = engine.compile(&self.filter);
|
||||
if let Ok(ast) = ast {
|
||||
let groups = state.word_groups.read();
|
||||
let query = state
|
||||
.dictionary.read().query_par(| word: &WordData|{
|
||||
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();
|
||||
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)
|
||||
.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",
|
||||
group_name,
|
||||
);
|
||||
|
||||
let result = engine.eval_ast_with_scope::<bool>(&mut scope, &ast);
|
||||
if let Ok(result) = result {
|
||||
return result;
|
||||
}
|
||||
false
|
||||
});
|
||||
|
||||
|
||||
info!("Collecting available words is {:?}", time.elapsed());
|
||||
|
||||
list
|
||||
} else {
|
||||
list
|
||||
}
|
||||
todo!()
|
||||
// let time = Instant::now();
|
||||
// let mut list = vec![];
|
||||
// let engine = Engine::new();
|
||||
//
|
||||
// let ast = engine.compile(&self.filter);
|
||||
// if let Ok(ast) = ast {
|
||||
// let groups = state.word_groups.read();
|
||||
// let query = state
|
||||
// .dictionary.read().query_par(| word: &WordData|{
|
||||
// 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();
|
||||
// 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)
|
||||
// .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",
|
||||
// group_name,
|
||||
// );
|
||||
//
|
||||
// let result = engine.eval_ast_with_scope::<bool>(&mut scope, &ast);
|
||||
// if let Ok(result) = result {
|
||||
// return result;
|
||||
// }
|
||||
// false
|
||||
// });
|
||||
//
|
||||
//
|
||||
// info!("Collecting available words is {:?}", time.elapsed());
|
||||
//
|
||||
// list
|
||||
// } else {
|
||||
// list
|
||||
// }
|
||||
}
|
||||
pub fn require_speech(&self) -> bool {
|
||||
self.forward == "speech" || self.backward == "speech"
|
||||
|
||||
@@ -9,6 +9,7 @@ use rayon::iter::ParallelIterator;
|
||||
use rusqlite::Connection;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use crate::data_provider::sqlite::SqliteConnection;
|
||||
|
||||
@@ -94,13 +95,15 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Query<T, R, D>
|
||||
where
|
||||
R: Repository<T, D>,
|
||||
D: DbLayer<T>,
|
||||
{
|
||||
cache: Vec<EntityHandle<T>>,
|
||||
rule: Box<dyn Fn(&T) -> bool + Send + Sync>,
|
||||
rule: Arc<dyn Fn(&T) -> bool + Send + Sync>,
|
||||
parallel: bool,
|
||||
_marker: PhantomData<(R, D)>,
|
||||
shift_stamp: usize,
|
||||
@@ -140,7 +143,7 @@ impl<T: EntityData + Clone + Send + Sync, R: Repository<T, D>, D: DbLayer<T>> Qu
|
||||
.cache
|
||||
.par_iter()
|
||||
.enumerate()
|
||||
.filter(|(_, entity)| (self.rule)(entity))
|
||||
.filter(|(_, entity)| self.rule.as_ref()(entity))
|
||||
.map(|(i, entity)| EntityHandle::new(entity.id(), i, true))
|
||||
.collect();
|
||||
} 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> {
|
||||
pub fn query_par(
|
||||
&self,
|
||||
rule: Box<dyn Fn(&T) -> bool + Send + Sync>,
|
||||
rule: Arc<dyn Fn(&T) -> bool + Send + Sync>,
|
||||
) -> Query<T, DataRepositoryInner<T, D>, D>
|
||||
where
|
||||
T: Send + Sync,
|
||||
@@ -267,7 +270,7 @@ impl<T: EntityData + Clone, D: DbLayer<T>> DataRepositoryInner<T, D> {
|
||||
|
||||
pub fn query(
|
||||
&self,
|
||||
rule: Box<dyn Fn(&T) -> bool + Send + Sync>,
|
||||
rule: Arc<dyn Fn(&T) -> bool + Send + Sync>,
|
||||
) -> Query<T, DataRepositoryInner<T, D>, D>
|
||||
where
|
||||
T: Send + Sync,
|
||||
|
||||
Reference in new issue
Block a user