insert UndoPoint appropriately into the replica operations
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
use crate::server::{Server, SyncOp};
|
||||
use crate::storage::{Storage, TaskMap};
|
||||
use crate::storage::{ReplicaOp, Storage, TaskMap};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[cfg(test)]
|
||||
use crate::storage::ReplicaOp;
|
||||
|
||||
mod apply;
|
||||
mod snapshot;
|
||||
mod sync;
|
||||
@@ -43,6 +40,13 @@ impl TaskDb {
|
||||
apply::apply(txn.as_mut(), op)
|
||||
}
|
||||
|
||||
/// Add an UndoPoint operation to the list of replica operations.
|
||||
pub fn add_undo_point(&mut self) -> anyhow::Result<()> {
|
||||
let mut txn = self.storage.txn()?;
|
||||
txn.add_operation(ReplicaOp::UndoPoint)?;
|
||||
txn.commit()
|
||||
}
|
||||
|
||||
/// Get all tasks.
|
||||
pub fn all_tasks(&mut self) -> anyhow::Result<Vec<(Uuid, TaskMap)>> {
|
||||
let mut txn = self.storage.txn()?;
|
||||
@@ -171,6 +175,13 @@ mod tests {
|
||||
assert_eq!(db.operations(), vec![ReplicaOp::Create { uuid }]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add_undo_point() {
|
||||
let mut db = TaskDb::new_inmemory();
|
||||
db.add_undo_point().unwrap();
|
||||
assert_eq!(db.operations(), vec![ReplicaOp::UndoPoint]);
|
||||
}
|
||||
|
||||
fn newdb() -> TaskDb {
|
||||
TaskDb::new(Box::new(InMemoryStorage::new()))
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ pub(super) fn sync(
|
||||
let mut local_ops: Vec<SyncOp> = txn
|
||||
.operations()?
|
||||
.drain(..)
|
||||
.map(|op| op.into_sync())
|
||||
.filter_map(|op| op.into_sync())
|
||||
.collect();
|
||||
|
||||
// first pull changes and "rebase" on top of them
|
||||
|
||||
Reference in New Issue
Block a user