FIX: never flush timings while in progress

Also reset last flush counter when we finally get a response from server.
This commit is contained in:
Sam 2018-01-19 08:27:17 +11:00
parent 12872d03be
commit 873624c487
1 changed files with 6 additions and 1 deletions

View File

@ -66,6 +66,7 @@ export default class {
this._totalTimings = {}; this._totalTimings = {};
this._topicTime = 0; this._topicTime = 0;
this._onscreen = []; this._onscreen = [];
this._inProgress = false;
} }
scrolled() { scrolled() {
@ -108,6 +109,7 @@ export default class {
if (!$.isEmptyObject(newTimings)) { if (!$.isEmptyObject(newTimings)) {
if (this.currentUser) { if (this.currentUser) {
this._inProgress = true;
ajax('/topics/timings', { ajax('/topics/timings', {
data: { data: {
timings: newTimings, timings: newTimings,
@ -128,6 +130,9 @@ export default class {
}).catch(e => { }).catch(e => {
const error = e.jqXHR; const error = e.jqXHR;
if (error.status === 405 && error.responseJSON.error_type === "read_only") return; if (error.status === 405 && error.responseJSON.error_type === "read_only") return;
}).finally(() => {
this._inProgress = false;
this._lastFlush = 0;
}); });
} else if (this._anonCallback) { } else if (this._anonCallback) {
// Anonymous viewer - save to localStorage // Anonymous viewer - save to localStorage
@ -182,7 +187,7 @@ export default class {
return timings[postNumber] > 0 && !totalTimings[postNumber]; return timings[postNumber] > 0 && !totalTimings[postNumber];
}); });
if (this._lastFlush > nextFlush || rush) { if (!this._inProgress && (this._lastFlush > nextFlush || rush)) {
this.flush(); this.flush();
} }