diff --git a/src/static/js/revisioncache.js b/src/static/js/revisioncache.js index 1a18d28cb..f5dc5a383 100644 --- a/src/static/js/revisioncache.js +++ b/src/static/js/revisioncache.js @@ -23,7 +23,7 @@ // of the document. These revisions are connected together by various // changesets, or deltas, between any two revisions. -require('./jquery.class'); +//require('./jquery.class'); $.Class("Changeset", {//statics @@ -144,7 +144,7 @@ $.Class("RevisionCache", // which is closer to our target, so we should push that changeset to // the list and move to that new revision to continue building a path var delta_rev = this.getRevision(current_rev.revnum + current_changeset.deltarev); - if (delta_rev.lt(to_rev, is_reverse) { + if (delta_rev.lt(to_rev, is_reverse)) { changesets.push(current_changeset); current_rev = delta_rev; break; @@ -153,7 +153,6 @@ $.Class("RevisionCache", if (stop || current_rev == old_rev) break; } - var status = 'partial'; if (current_rev == to_rev) status = 'complete'; @@ -163,66 +162,6 @@ $.Class("RevisionCache", 'rev': current_rev.rev, 'status': status, 'changesets': changesets, - /*'spans': spans, - 'times': times - */ - }; - }, - findPath: function (from, to) { - var current_rev = this.getRevision(from); - var to_rev = this.getRevision(to); - var is_reverse = !(from < to); - var changesets = []; - - if (from == to) { - //TODO: implement short-circuit - } - - if (!current_rev.changesets.length) { - // You cannot build a path if the starting revision hasn't - // got any changesets - //TODO: implement short-circuit - } - - while (current_rev.lt(to_rev)) { - for (var i = 0; i < current_rev.changesets.length; i++) { - // we might get stuck on a particular revision if only a - // partial path is available. - old_rev = current_rev; - // the next (first) changeset in the current revision has a delta - // in the opposite direction to that in which we are trying to - // move, and so cannot help us. Because the changeset list is - // sorted, we can just stop here. - if (current_rev.changesets[i].deltarev < 0) { - // When can this happen? - stop = true; - } - - // the current revision has a changeset which helps us get to a revision - // which is closer to our target, so we should push that changeset to - // the list and move to that new revision to continue building a path - if (current_rev.revnum + current_rev.changesets[i].deltarev <= to) { - changesets.push(current_rev.changesets[i]); - current_rev = this.getRevision(current_rev.rev + current_rev.changesets[i].deltarev); - break; - } - } - if (stop || current_rev == old_rev) - break; - } - - var status = 'partial'; - if (current_rev == to_rev) - status = 'complete'; - - return { - 'fromRev': from, - 'rev': current_rev.rev, - 'status': status, - 'changesets': changesets, - /*'spans': spans, - 'times': times - */ }; }, addChangeset: function (from, to, value, reverseValue, timedelta) { @@ -233,12 +172,96 @@ $.Class("RevisionCache", } } ); + +$.Class("Thread", + {//statics + }, + {//instance + init: function () { + this.is_running = false; + this.is_stopping = false; + this._interval_id = null; + }, + _run: function () { + console.log("[thread] tick"); + }, + // start the run loop + start: function () { + var _this = this; + console.log("[thread] starting") + var wrapper = function () { + if (_this.is_running && _this.is_stopping) { + console.log("[thread] shutting down") + clearInterval(_this._interval_id); + _this.is_running = false; + return; + } + _this._run.apply(_this); + }; + this._interval_id = setInterval(wrapper, 1000); + this.is_running = true; + }, + // stop the run loop + stop: function () { + this.is_stopping = true; + console.log("[thread] request stop") + // TODO: consider finding a way to make this block + // or alternatively, having a callback which is called + // when the thread stops + } + } +); + +$.Class("ChangesetRequest", + {//statics + }, + {//instance + init: function (start, end) { + this.start = start; + this.end = end; + } + } +); + +Thread("ChangesetLoader", + {//statics + }, + {//instance + init: function () { + this._super(); + this.queue_large = []; + this.queue_medium = []; + this.queue_small = []; + }, + enqueue: function (start, count) { + //TODO: check cache to see if we really need to fetch this + // maybe even to splices if we just need a smaller range + // in the middle + var queue = null; + if (count >= 100) + queue = this.queue_large; + else if (count >= 10) + queue = this.queue_medium; + else + queue = this.queue_small; + + queue.push(new ChangesetRequest(start, start+count)); + }, + _run: function () { + console.log("[changesetloader] tick"); + //TODO: pop an item from the queue and perform a request. + + }, + } +); function loadBroadcastRevisionsJS(clientVars) { + console.log("here") revisionCache = new RevisionCache(clientVars.collab_client_vars.rev || 0); revisionInfo.latest = clientVars.collab_client_vars.rev || -1; +// cl = new ChangesetLoader(); }