Поправки синхронизации
This commit is contained in:
@@ -542,10 +542,12 @@ class Reader extends Vue {
|
|||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
await utils.sleep(500);
|
await utils.sleep(500);
|
||||||
while (!this.$refs.serverStorage.inited) await utils.sleep(100);
|
while (!this.$refs.serverStorage.inited ||
|
||||||
while (!bookManager.loaded) await utils.sleep(100);
|
!bookManager.loaded ||
|
||||||
|
this.$refs.serverStorage.savingRecent)
|
||||||
|
await utils.sleep(100);
|
||||||
|
|
||||||
this.$refs.serverStorage.saveRecent(value);
|
await this.$refs.serverStorage.saveRecent(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -435,64 +435,64 @@ class ServerStorage extends Vue {
|
|||||||
if (!this.keyInited || !this.serverSyncEnabled || this.savingRecent)
|
if (!this.keyInited || !this.serverSyncEnabled || this.savingRecent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const bm = bookManager;
|
|
||||||
|
|
||||||
let needSaveRecent = false;
|
|
||||||
let needSaveRecentPatch = false;
|
|
||||||
let needSaveRecentMod = false;
|
|
||||||
|
|
||||||
//newRecentMod
|
|
||||||
let newRecentMod = {};
|
|
||||||
if (itemKey && this.cachedRecentPatch.data[itemKey] && this.prevItemKey == itemKey) {
|
|
||||||
newRecentMod = _.cloneDeep(this.cachedRecentMod);
|
|
||||||
newRecentMod.rev++;
|
|
||||||
|
|
||||||
newRecentMod.data.key = itemKey;
|
|
||||||
newRecentMod.data.mod = utils.getObjDiff(this.cachedRecentPatch.data[itemKey], bm.recent[itemKey]);
|
|
||||||
needSaveRecentMod = true;
|
|
||||||
}
|
|
||||||
this.prevItemKey = itemKey;
|
|
||||||
|
|
||||||
//newRecentPatch
|
|
||||||
let newRecentPatch = {};
|
|
||||||
if (itemKey && !needSaveRecentMod) {
|
|
||||||
newRecentPatch = _.cloneDeep(this.cachedRecentPatch);
|
|
||||||
newRecentPatch.rev++;
|
|
||||||
newRecentPatch.data[itemKey] = bm.recent[itemKey];
|
|
||||||
|
|
||||||
let applyMod = this.cachedRecentMod.data;
|
|
||||||
if (applyMod && applyMod.key && newRecentPatch.data[applyMod.key])
|
|
||||||
newRecentPatch.data[applyMod.key] = utils.applyObjDiff(newRecentPatch.data[applyMod.key], applyMod.mod);
|
|
||||||
|
|
||||||
newRecentMod = {rev: this.cachedRecentMod.rev + 1, data: {}};
|
|
||||||
needSaveRecentPatch = true;
|
|
||||||
needSaveRecentMod = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//newRecent
|
|
||||||
let newRecent = {};
|
|
||||||
if (!itemKey || (needSaveRecentPatch && Object.keys(newRecentPatch.data).length > 10)) {
|
|
||||||
newRecent = {rev: this.cachedRecent.rev + 1, data: bm.recent};
|
|
||||||
newRecentPatch = {rev: this.cachedRecentPatch.rev + 1, data: {}};
|
|
||||||
newRecentMod = {rev: this.cachedRecentMod.rev + 1, data: {}};
|
|
||||||
needSaveRecent = true;
|
|
||||||
needSaveRecentPatch = true;
|
|
||||||
needSaveRecentMod = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//query
|
|
||||||
let query = {};
|
|
||||||
if (needSaveRecent) {
|
|
||||||
query = {recent: newRecent, recentPatch: newRecentPatch, recentMod: newRecentMod};
|
|
||||||
} else if (needSaveRecentPatch) {
|
|
||||||
query = {recentPatch: newRecentPatch, recentMod: newRecentMod};
|
|
||||||
} else {
|
|
||||||
query = {recentMod: newRecentMod};
|
|
||||||
}
|
|
||||||
|
|
||||||
//сохранение
|
|
||||||
this.savingRecent = true;
|
this.savingRecent = true;
|
||||||
try {
|
try {
|
||||||
|
const bm = bookManager;
|
||||||
|
|
||||||
|
let needSaveRecent = false;
|
||||||
|
let needSaveRecentPatch = false;
|
||||||
|
let needSaveRecentMod = false;
|
||||||
|
|
||||||
|
//newRecentMod
|
||||||
|
let newRecentMod = {};
|
||||||
|
if (itemKey && this.cachedRecentPatch.data[itemKey] && this.prevItemKey == itemKey) {
|
||||||
|
newRecentMod = _.cloneDeep(this.cachedRecentMod);
|
||||||
|
newRecentMod.rev++;
|
||||||
|
|
||||||
|
newRecentMod.data.key = itemKey;
|
||||||
|
newRecentMod.data.mod = utils.getObjDiff(this.cachedRecentPatch.data[itemKey], bm.recent[itemKey]);
|
||||||
|
needSaveRecentMod = true;
|
||||||
|
}
|
||||||
|
this.prevItemKey = itemKey;
|
||||||
|
|
||||||
|
//newRecentPatch
|
||||||
|
let newRecentPatch = {};
|
||||||
|
if (itemKey && !needSaveRecentMod) {
|
||||||
|
newRecentPatch = _.cloneDeep(this.cachedRecentPatch);
|
||||||
|
newRecentPatch.rev++;
|
||||||
|
newRecentPatch.data[itemKey] = bm.recent[itemKey];
|
||||||
|
|
||||||
|
let applyMod = this.cachedRecentMod.data;
|
||||||
|
if (applyMod && applyMod.key && newRecentPatch.data[applyMod.key])
|
||||||
|
newRecentPatch.data[applyMod.key] = utils.applyObjDiff(newRecentPatch.data[applyMod.key], applyMod.mod);
|
||||||
|
|
||||||
|
newRecentMod = {rev: this.cachedRecentMod.rev + 1, data: {}};
|
||||||
|
needSaveRecentPatch = true;
|
||||||
|
needSaveRecentMod = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//newRecent
|
||||||
|
let newRecent = {};
|
||||||
|
if (!itemKey || (needSaveRecentPatch && Object.keys(newRecentPatch.data).length > 10)) {
|
||||||
|
newRecent = {rev: this.cachedRecent.rev + 1, data: bm.recent};
|
||||||
|
newRecentPatch = {rev: this.cachedRecentPatch.rev + 1, data: {}};
|
||||||
|
newRecentMod = {rev: this.cachedRecentMod.rev + 1, data: {}};
|
||||||
|
needSaveRecent = true;
|
||||||
|
needSaveRecentPatch = true;
|
||||||
|
needSaveRecentMod = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//query
|
||||||
|
let query = {};
|
||||||
|
if (needSaveRecent) {
|
||||||
|
query = {recent: newRecent, recentPatch: newRecentPatch, recentMod: newRecentMod};
|
||||||
|
} else if (needSaveRecentPatch) {
|
||||||
|
query = {recentPatch: newRecentPatch, recentMod: newRecentMod};
|
||||||
|
} else {
|
||||||
|
query = {recentMod: newRecentMod};
|
||||||
|
}
|
||||||
|
|
||||||
|
//сохранение
|
||||||
let result = {state: ''};
|
let result = {state: ''};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user