mirror of
https://git.alemi.dev/memo-cli.git
synced 2024-11-22 10:04:50 +01:00
should mostly fix merge policy
This commit is contained in:
parent
5ab9f2c5af
commit
37e95efda4
1 changed files with 6 additions and 3 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue