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();
let mut data: Vec<u8> = vec![0; 0];
let mut data: Vec<u8> = Vec::new();
resp.read_to_end(&mut data)?;
// TODO decrypt
@ -35,7 +35,7 @@ pub trait RemoteSync : AuthStorage+MemoStorage+Sized {
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 memo_ids : HashSet<Uuid> = HashSet::new();
for memo in self.all(false)?.iter() {
@ -47,7 +47,10 @@ pub trait RemoteSync : AuthStorage+MemoStorage+Sized {
for memo in other.all(true)?.iter() {
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 {
self.insert(memo.clone())?;
count += 1;