Rewrite history page
This commit is contained in:
1 parent
f19a6f64c3
commit
532640058e
11 files changed
+201
-230
No files matched your search
@@ -188,7 +188,7 @@ impl<T: EntityData + Clone + Send + Sync, R: Repository<T, D>, D: DbLayer<T>> Qu
|
||||
);
|
||||
}
|
||||
|
||||
pub fn handles(&self, data_repository: &DataRepositoryInner<T, D>) -> impl Iterator<Item = EntityHandle<T>> {
|
||||
pub fn handles(&self) -> impl Iterator<Item = EntityHandle<T>> {
|
||||
self.cache.iter().cloned()
|
||||
}
|
||||
|
||||
@@ -216,6 +216,7 @@ where
|
||||
D: BatchedDbLayer<T>,
|
||||
T: EntityData,
|
||||
{
|
||||
fn create_now_many(&mut self, entities: &mut [T]) -> Result<Vec<EntityHandle<T>>, NotificationData>;
|
||||
fn save_many(&mut self, handles: &mut [EntityHandle<T>]) -> MaybeError;
|
||||
fn delete_many(&mut self, handles: &mut [EntityHandle<T>]) -> MaybeError;
|
||||
}
|
||||
@@ -236,11 +237,11 @@ where
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DataRepository<T: std::clone::Clone + EntityData, D: DbLayer<T>> {
|
||||
pub struct DataRepository<T: Clone + EntityData, D: DbLayer<T>> {
|
||||
inner: Arc<RwLock<DataRepositoryInner<T, D>>>,
|
||||
}
|
||||
|
||||
pub struct DataRepositoryInner<T: std::clone::Clone + EntityData, D: DbLayer<T>> {
|
||||
pub struct DataRepositoryInner<T: Clone + EntityData, D: DbLayer<T>> {
|
||||
cache: Vec<T>,
|
||||
temporal: Vec<T>,
|
||||
next_temporal: u32,
|
||||
@@ -251,7 +252,7 @@ pub struct DataRepositoryInner<T: std::clone::Clone + EntityData, D: DbLayer<T>>
|
||||
shifts: usize,
|
||||
}
|
||||
|
||||
impl<T: std::clone::Clone + EntityData, D: DbLayer<T> + std::default::Default> DataRepository<T, D> {
|
||||
impl<T: Clone + EntityData, D: DbLayer<T> + Default> DataRepository<T, D> {
|
||||
pub fn new(connection: Arc<RwLock<SqliteConnection>>) -> DataRepository<T, D> {
|
||||
Self{
|
||||
inner: Arc::new(RwLock::new(DataRepositoryInner{
|
||||
@@ -269,7 +270,7 @@ impl<T: std::clone::Clone + EntityData, D: DbLayer<T> + std::default::Default>
|
||||
}
|
||||
|
||||
|
||||
impl<T: std::clone::Clone + EntityData, D: DbLayer<T>> Deref for DataRepository<T, D> {
|
||||
impl<T: Clone + EntityData, D: DbLayer<T>> Deref for DataRepository<T, D> {
|
||||
type Target = Arc<RwLock<DataRepositoryInner<T, D>>>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
@@ -313,7 +314,7 @@ impl<T: EntityData + Clone, D: DbLayer<T>> DataRepositoryInner<T, D> {
|
||||
|
||||
pub fn query(
|
||||
&self,
|
||||
rule: Arc<dyn Fn(&T) -> bool + Send + Sync>,
|
||||
rule: Arc<dyn Fn(& T) -> bool + Send + Sync>,
|
||||
) -> Query<T, DataRepositoryInner<T, D>, D>
|
||||
where
|
||||
T: Send + Sync,
|
||||
@@ -536,6 +537,14 @@ impl<T: EntityData + Clone, D: DbLayer<T>> Repository<T, D> for DataRepositoryIn
|
||||
impl<T: EntityData + Clone, D: BatchedDbLayer<T> + DbLayer<T>> BatchedRepository<T, D>
|
||||
for DataRepositoryInner<T, D>
|
||||
{
|
||||
fn create_now_many(&mut self, entities: &mut [T]) -> Result<Vec<EntityHandle<T>>, NotificationData> {
|
||||
self.data_layer.add_many_entities(entities, &mut self.connection.write())?;
|
||||
let len = self.cache.len();
|
||||
let handles = entities.iter().enumerate().map(|(index, entity)| {EntityHandle::new(entity.id(), index + len, true)}).collect();
|
||||
self.cache.extend(entities.to_vec());
|
||||
Ok(handles)
|
||||
}
|
||||
|
||||
fn save_many(&mut self, handles: &mut [EntityHandle<T>]) -> MaybeError {
|
||||
let mut temp = Vec::with_capacity(handles.len() / 2);
|
||||
let mut cached = Vec::with_capacity(handles.len() / 2);
|
||||
|
||||
Reference in new issue
Block a user