mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-15 15:41:19 +00:00
sync优化, 只有在content不一样的时候才认为conflict
This commit is contained in:
125
node_modules/sync.js
generated
vendored
125
node_modules/sync.js
generated
vendored
@@ -141,9 +141,9 @@ var Sync = {
|
||||
function canCall() {
|
||||
// 是最后一块, 且
|
||||
me._addSyncNotebookNum();
|
||||
console.log(me._syncNotebookIsLastChunk);
|
||||
console.log(me._totalHasSyncNotebookNum + ' ' + me._totalSyncNotebookNum);
|
||||
console.log(me._syncInfo.notebook.ok);
|
||||
// console.log(me._syncNotebookIsLastChunk);
|
||||
// console.log(me._totalHasSyncNotebookNum + ' ' + me._totalSyncNotebookNum);
|
||||
// console.log(me._syncInfo.notebook.ok);
|
||||
if(me._syncNotebookIsLastChunk &&
|
||||
me._totalHasSyncNotebookNum >= me._totalSyncNotebookNum) {
|
||||
// 防止多次callback
|
||||
@@ -171,8 +171,8 @@ var Sync = {
|
||||
|
||||
// 1) 服务器端删除了, 本地肯定删除
|
||||
if(notebook.IsDeleted) {
|
||||
console.log('delete: ');
|
||||
console.log(notebook);
|
||||
// console.log('delete: ');
|
||||
// console.log(notebook);
|
||||
Notebook.getNotebookIdByServerNotebookId(notebookId, function(localNotebookId) {
|
||||
Notebook.deleteNotebookForce(notebookId, function() {
|
||||
me._syncInfo.notebook.deletes.push(localNotebookId);
|
||||
@@ -332,6 +332,7 @@ var Sync = {
|
||||
|
||||
// 2.2 本地是否修改了, 冲突, 报告给前端, 前端处理
|
||||
// 冲突, 将本地修改的笔记复制一份(设置冲突字段, ConflictNoteId), 远程的覆盖本地的
|
||||
// 新方法: 冲突后, 得到最新内容, 看是否与本地内容一致, 如果一致, 则不冲突, 其它数据用服务器上的
|
||||
if(noteLocal.IsDirty) {
|
||||
console.log('note 冲突.... serverNoteId: ' + noteId);
|
||||
// console.log(noteLocal.NoteId);
|
||||
@@ -339,7 +340,28 @@ var Sync = {
|
||||
// console.log(noteLocal);
|
||||
// note.ServerNoteId = note.NoteId;
|
||||
// note.NoteId = noteLocal.NoteId;
|
||||
me._syncInfo.note.conflicts.push({server: note, local: noteLocal});
|
||||
|
||||
Note.getNoteContentFromServer(noteId, function (content) {
|
||||
// 表示没有获取到content, 则只能标志为冲突了
|
||||
// 内容不一样, 也标为冲突
|
||||
if (content === false || content != noteLocal.Content) {
|
||||
me._syncInfo.note.conflicts.push({server: note, local: noteLocal});
|
||||
}
|
||||
// 否则, 内容一样, 标为不冲突, 需要更新
|
||||
else {
|
||||
|
||||
// 2.3 服务器是最新的, 用服务器的
|
||||
// 服务器是最新的, 本地没动过, 则覆盖之
|
||||
Note.updateNoteForce(note, function(note) {
|
||||
if(note) {
|
||||
me._syncInfo.note.updates.push(note);
|
||||
}
|
||||
canCall();
|
||||
}, false);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return canCall();
|
||||
// 2.3 服务器是最新的, 用服务器的
|
||||
} else {
|
||||
@@ -364,7 +386,7 @@ var Sync = {
|
||||
}
|
||||
|
||||
Api.getSyncNotes(afterUsn, me._noteMaxEntry, function(notes) {
|
||||
console.log('syncNote---')
|
||||
console.log('syncNote---');
|
||||
console.log(notes);
|
||||
if(Common.isOk(notes)) {
|
||||
me._totalSyncNoteNum += notes.length;
|
||||
@@ -874,70 +896,55 @@ var Sync = {
|
||||
if(typeof ret == 'object') {
|
||||
if(ret.Msg == 'conflict') {
|
||||
console.error('updateNote 冲突-----------');
|
||||
me._syncInfo.note.changeConflicts.push(note);
|
||||
|
||||
// 这种情况有很少见, 原因是先pull, 肯定会pull过来
|
||||
// 处理方法和pull一样, 看内容是否一样
|
||||
// 如果一样, 则不标志为冲突, 修改本Usn为serverUsn, 等下次再send changes
|
||||
Note.getNoteContentFromServer(note.ServerNoteId, function (content) {
|
||||
if (content === false || content != note.LocalContent) {
|
||||
me._syncInfo.note.changeConflicts.push(note);
|
||||
cb();
|
||||
}
|
||||
else {
|
||||
// 不冲突, 修改之Usn
|
||||
Api.getNote(note.ServerNoteId, function (serverNote) {
|
||||
// 取不到, 当作冲突
|
||||
if (!serverNote) {
|
||||
me._syncInfo.note.changeConflicts.push(note);
|
||||
cb();
|
||||
}
|
||||
else {
|
||||
Note.updateNoteUsn(note.NoteId, serverNote.Usn);
|
||||
cb();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
else if(ret.Msg == 'notExists') {
|
||||
// 可能服务器上已删除, 此时应该要作为添加而不是更新
|
||||
me._syncInfo.note.changeNeedAdds.push(note);
|
||||
cb();
|
||||
}
|
||||
}
|
||||
return cb();
|
||||
// 更新失败了, 服务器返回异常
|
||||
else {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
// 更新成功
|
||||
// TODO 返回是真note
|
||||
ret.ServerNoteId = ret.NoteId;
|
||||
ret.NoteId = note.NoteId;
|
||||
Note.updateNoteForceForSendChange(ret, false);
|
||||
me._syncInfo.note.changeUpdates.push(note);
|
||||
else {
|
||||
ret.ServerNoteId = ret.NoteId;
|
||||
ret.NoteId = note.NoteId;
|
||||
Note.updateNoteForceForSendChange(ret, false);
|
||||
me._syncInfo.note.changeUpdates.push(note);
|
||||
|
||||
me.checkNeedIncSyncAgain(ret.Usn);
|
||||
me.checkNeedIncSyncAgain(ret.Usn);
|
||||
|
||||
return cb();
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//...... 过时
|
||||
/*
|
||||
api.call(Api, note, function(ret) {
|
||||
// 更新失败
|
||||
if(!newNote) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
// 删除操作
|
||||
if(note.LocalIsDelete) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
// 更新成功, 是否有冲突?
|
||||
// newNote是服务器上的笔记
|
||||
// 没有更新成功, 那么要处理冲突
|
||||
if(!newNote.NoteId) {
|
||||
if(newNote.Msg == 'conflict') {
|
||||
me._syncInfo.note.changeConflicts.push(note);
|
||||
} else if(newNote.Msg == 'notExists') {
|
||||
// 可能服务器上已删除, 此时应该要作为添加而不是更新
|
||||
me._syncInfo.note.changeNeedAdds.push(note);
|
||||
}
|
||||
}
|
||||
// 更新成功, 修改到本地
|
||||
else {
|
||||
// 更新
|
||||
Note.updateNoteForceForSendChange(note.NoteId, newNote);
|
||||
|
||||
if(note.LocalIsNew) {
|
||||
newNote.ServerNoteId = newNote.NoteId;
|
||||
newNote.NoteId = note.NoteId;
|
||||
me._syncInfo.note.changeAdds.push(newNote);
|
||||
} else {
|
||||
me._syncInfo.note.updates.push(newNote);
|
||||
}
|
||||
|
||||
me.checkNeedIncSyncAgain(newNote.Usn);
|
||||
}
|
||||
cb();
|
||||
});
|
||||
*/
|
||||
}, function() {
|
||||
callback && callback();
|
||||
});
|
||||
|
Reference in New Issue
Block a user