should mostly fix merge policy

This commit is contained in:
əlemi 2022-03-29 00:45:16 +02:00
parent 5ab9f2c5af
commit 37e95efda4
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -26,7 +26,7 @@ pub trait RemoteSync : AuthStorage+MemoStorage+Sized {
}))? }))?
.into_reader(); .into_reader();
let mut data: Vec<u8> = vec![0; 0]; let mut data: Vec<u8> = Vec::new();
resp.read_to_end(&mut data)?; resp.read_to_end(&mut data)?;
// TODO decrypt // TODO decrypt
@ -35,7 +35,7 @@ pub trait RemoteSync : AuthStorage+MemoStorage+Sized {
return Ok(self.merge(&other).unwrap()); return Ok(self.merge(&other).unwrap());
} }
fn merge(&mut self, other: &Self) -> Result<usize, MemoError> { // TODO don't use error specific to rusqlite fn merge(&mut self, other: &Self) -> Result<usize, MemoError> {
let mut count = 0; let mut count = 0;
let mut memo_ids : HashSet<Uuid> = HashSet::new(); let mut memo_ids : HashSet<Uuid> = HashSet::new();
for memo in self.all(false)?.iter() { for memo in self.all(false)?.iter() {
@ -47,7 +47,10 @@ pub trait RemoteSync : AuthStorage+MemoStorage+Sized {
for memo in other.all(true)?.iter() { for memo in other.all(true)?.iter() {
if memo_ids.contains(&memo.id) { if memo_ids.contains(&memo.id) {
self.set(memo)?; // TODO only replace if more recently edited!! let old_memo = self.get(&memo.id)?;
if memo.last_edit > old_memo.last_edit {
self.set(memo)?;
}
} else { } else {
self.insert(memo.clone())?; self.insert(memo.clone())?;
count += 1; count += 1;