Clear code and add shifts into Query
This commit is contained in:
1 parent
ea214d8ac0
commit
b006ece0c1
1 file changed
+8
-2
@@ -7,10 +7,8 @@ use rayon::iter::IndexedParallelIterator;
|
||||
use rayon::iter::IntoParallelRefIterator;
|
||||
use rayon::iter::ParallelIterator;
|
||||
use rusqlite::Connection;
|
||||
use std::cell::RefCell;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::Deref;
|
||||
use std::rc::Weak;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub trait Repository<T, D>
|
||||
@@ -100,6 +98,7 @@ where
|
||||
rule: Box<dyn Fn(&T) -> bool + Send + Sync>,
|
||||
parallel: bool,
|
||||
_marker: PhantomData<(R, D)>,
|
||||
shift_stamp: u16
|
||||
}
|
||||
|
||||
impl<T: EntityData + Clone, R: Repository<T, D>, D: DbLayer<T>> Query<T, R, D> {
|
||||
@@ -195,6 +194,7 @@ pub struct DataRepositoryInner<T: std::clone::Clone + EntityData, D: DbLayer<T>>
|
||||
data_layer: D,
|
||||
query_manger: QueryManger<T, Self, D>,
|
||||
version: u16,
|
||||
shifts: u16,
|
||||
}
|
||||
|
||||
impl<T: std::clone::Clone + EntityData, D: DbLayer<T>> Deref for DataRepository<T, D> {
|
||||
@@ -235,6 +235,7 @@ impl<T: EntityData + Clone, D: DbLayer<T>> DataRepositoryInner<T, D> {
|
||||
rule,
|
||||
parallel: true,
|
||||
_marker: PhantomData,
|
||||
shift_stamp: self.shifts,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,6 +268,7 @@ impl<T: EntityData + Clone, D: DbLayer<T>> DataRepositoryInner<T, D> {
|
||||
rule,
|
||||
parallel: false,
|
||||
_marker: PhantomData,
|
||||
shift_stamp: self.shifts,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -332,6 +334,7 @@ impl<T: EntityData + Clone, D: DbLayer<T>> Repository<T, D> for DataRepositoryIn
|
||||
self.query_manger.handle_save(original_state, entity, &data);
|
||||
|
||||
self.cache.push(data);
|
||||
self.shifts += 1;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -352,6 +355,7 @@ impl<T: EntityData + Clone, D: DbLayer<T>> Repository<T, D> for DataRepositoryIn
|
||||
)?;
|
||||
let value = vec.remove(index);
|
||||
self.query_manger.handle_delete(&handle, &value);
|
||||
self.shifts += 1;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -421,6 +425,7 @@ impl<T: EntityData + Clone, D: BatchedDbLayer<T> + DbLayer<T>> BatchedRepository
|
||||
self.data_layer
|
||||
.write_entity(&self.cache[idx], &self.connection.read())?;
|
||||
}
|
||||
self.shifts += 1;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -457,6 +462,7 @@ impl<T: EntityData + Clone, D: BatchedDbLayer<T> + DbLayer<T>> BatchedRepository
|
||||
|
||||
!remove
|
||||
});
|
||||
self.shifts += 1;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user