Работа над ServerStorage, попутные оптимизации

This commit is contained in:
Book Pauk
2019-03-20 14:34:01 +07:00
parent 826ee18666
commit b12198fdcf
2 changed files with 47 additions and 9 deletions

View File

@@ -46,6 +46,7 @@ class ServerStorage extends Vue {
this.oldProfiles = {};
this.oldSettings = {};
this.oldRecent = {};
}
async init() {
@@ -243,7 +244,7 @@ class ServerStorage extends Vue {
//проверим ревизию на сервере
if (!force) {
try {
const revs = await this.storageCheck({'profiles': {}});
const revs = await this.storageCheck({profiles: {}});
if (revs.state == 'success' && revs.items.profiles.rev == oldRev) {
return;
}
@@ -255,7 +256,7 @@ class ServerStorage extends Vue {
let prof = null;
try {
prof = await this.storageGet({'profiles': {}});
prof = await this.storageGet({profiles: {}});
} catch(e) {
this.error(`Ошибка соединения с сервером: ${e.message}`);
return;
@@ -297,7 +298,7 @@ class ServerStorage extends Vue {
let tries = 0;
while (result.state != 'success' && tries < maxSetTries) {
try {
result = await this.storageSet({'profiles': {rev: this.profilesRev + 1, data: this.profiles}});
result = await this.storageSet({profiles: {rev: this.profilesRev + 1, data: this.profiles}});
} catch(e) {
this.savingProfiles = false;
this.commit('reader/setProfiles', this.oldProfiles);
@@ -329,7 +330,46 @@ class ServerStorage extends Vue {
}
}
async loadRecent() {
async loadRecent(force) {
if (!this.serverSyncEnabled)
return;
const oldRev = bookManager.recentRev;
//проверим ревизию на сервере
if (!force) {
try {
const revs = await this.storageCheck({recent: {}});
if (revs.state == 'success' && revs.items.recent.rev == oldRev) {
return;
}
} catch(e) {
this.error(`Ошибка соединения с сервером: ${e.message}`);
return;
}
}
let recent = null;
try {
recent = await this.storageGet({recent: {}});
} catch(e) {
this.error(`Ошибка соединения с сервером: ${e.message}`);
return;
}
if (recent.state == 'success') {
recent = recent.items.recent;
if (recent.rev == 0)
recent.data = {};
this.oldRecent = _.cloneDeep(recent.data);
bookManager.setRecent(recent.data);
bookManager.setRecentRev(recent.rev);
this.notifySuccessIfNeeded(oldRev, recent.rev);
} else {
this.warning(`Неверный ответ сервера: ${recent.state}`);
}
}
async storageCheck(items) {

View File

@@ -39,7 +39,6 @@ class BookManager {
this.recentLastRev = bmRecentStore.getItem('recent-last-rev') || 0;
this.books = Object.assign({}, this.booksCached);
this.recentChanged1 = true;
this.recentChanged2 = true;
if (!this.books || !this.recent) {
@@ -264,7 +263,7 @@ class BookManager {
await bmCacheStore.setItem('recent-last', this.recentLast);
this.emit('recent-last-changed');
this.recentChanged1 = true;
this.mostRecentCached = result;
this.recentChanged2 = true;
return result;
}
@@ -284,7 +283,7 @@ class BookManager {
await bmCacheStore.setItem('recent', this.recent);
this.emit('recent-changed');
this.recentChanged1 = true;
this.mostRecentCached = null;
this.recentChanged2 = true;
}
@@ -313,7 +312,7 @@ class BookManager {
}
mostRecentBook() {
if (!this.recentChanged1 && this.mostRecentCached) {
if (this.mostRecentCached) {
return this.mostRecentCached;
}
@@ -327,7 +326,6 @@ class BookManager {
}
}
this.mostRecentCached = result;
this.recentChanged1 = false;
return result;
}