mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
Workaround for granularity issue.
Just return the granularity discovered to be empty from findPath and provide it to requestChangesets. This is very sub-optimal, as it will almost always result in granularity==1.
This commit is contained in:
parent
275c26f872
commit
1c6012b29f
1 changed files with 28 additions and 16 deletions
|
@ -212,11 +212,16 @@ $.Class("RevisionCache",
|
||||||
var found_discontinuity = false;
|
var found_discontinuity = false;
|
||||||
var current = from;
|
var current = from;
|
||||||
var direction = (to.revnum - from.revnum) < 0;
|
var direction = (to.revnum - from.revnum) < 0;
|
||||||
|
var granularity = 0;
|
||||||
|
|
||||||
|
console.log("[findpath] from: %d, to: %d", from.revnum, to.revnum);
|
||||||
while (current.lt(to, direction) && !found_discontinuity) {
|
while (current.lt(to, direction) && !found_discontinuity) {
|
||||||
|
console.log("\t[findPath] while current: ", current.revnum);
|
||||||
var delta_revnum = to.revnum - current.revnum;
|
var delta_revnum = to.revnum - current.revnum;
|
||||||
var direction_edges = direction ? current.previous : current.next;
|
var direction_edges = direction ? current.previous : current.next;
|
||||||
for (var granularity in Revision.granularities) {
|
for (granularity in Revision.granularities) {
|
||||||
if (Math.abs(delta_revnum) >= Revision.granularities[granularity]) {
|
if (Math.abs(delta_revnum) >= Revision.granularities[granularity]) {
|
||||||
|
console.log("\t\t[findPath] for delta: %d, granularity: %d", delta_revnum, Revision.granularities[granularity]);
|
||||||
/*
|
/*
|
||||||
* the delta is larger than the granularity, let's use the granularity
|
* the delta is larger than the granularity, let's use the granularity
|
||||||
*TODO: what happens if we DON'T have the edge?
|
*TODO: what happens if we DON'T have the edge?
|
||||||
|
@ -226,6 +231,7 @@ $.Class("RevisionCache",
|
||||||
* from current to that Revision (at the largest possible granularity)
|
* from current to that Revision (at the largest possible granularity)
|
||||||
*/
|
*/
|
||||||
var edge = direction_edges[granularity];
|
var edge = direction_edges[granularity];
|
||||||
|
console.log("\t\t[findpath] edge:", edge);
|
||||||
if (edge) {
|
if (edge) {
|
||||||
// add this edge to our path
|
// add this edge to our path
|
||||||
path.push(edge);
|
path.push(edge);
|
||||||
|
@ -245,9 +251,10 @@ $.Class("RevisionCache",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("[findpath] ------------------");
|
||||||
// return either a full path, or a path ending as close as we can get to
|
// return either a full path, or a path ending as close as we can get to
|
||||||
// the target revision.
|
// the target revision.
|
||||||
return {path: path, end_revision: current};
|
return {path: path, end_revision: current, granularity: granularity};
|
||||||
},
|
},
|
||||||
//TODO: horrible name!
|
//TODO: horrible name!
|
||||||
transition: function (from_revnum, to_revnum, applyChangeset_callback) {
|
transition: function (from_revnum, to_revnum, applyChangeset_callback) {
|
||||||
|
@ -289,7 +296,7 @@ $.Class("RevisionCache",
|
||||||
console.log(print_path(res.path));
|
console.log(print_path(res.path));
|
||||||
// we can now request changesets from the end of that partial path
|
// we can now request changesets from the end of that partial path
|
||||||
// to the target:
|
// to the target:
|
||||||
_this.requestChangesets(res.end_revision, target_revision, partialTransition);
|
_this.requestChangesets(res.end_revision, target_revision, res.granularity, partialTransition);
|
||||||
}
|
}
|
||||||
|
|
||||||
partialTransition(from_revnum);
|
partialTransition(from_revnum);
|
||||||
|
@ -300,11 +307,12 @@ $.Class("RevisionCache",
|
||||||
* from the server.
|
* from the server.
|
||||||
* @param {Revision} from - The start revision.
|
* @param {Revision} from - The start revision.
|
||||||
* @param {Revision} to - The end revision.
|
* @param {Revision} to - The end revision.
|
||||||
|
* @param {number} granularity - The granularity at which to request.
|
||||||
* @param {function} changesetsProcessed_callback - A callback triggered
|
* @param {function} changesetsProcessed_callback - A callback triggered
|
||||||
* when the requested changesets have been
|
* when the requested changesets have been
|
||||||
* received and processed (added to the graph)
|
* received and processed (added to the graph)
|
||||||
*/
|
*/
|
||||||
requestChangesets: function (from, to, changesetsProcessed_callback) {
|
requestChangesets: function (from, to, granularity, changesetsProcessed_callback) {
|
||||||
console.log("[revisioncache] requestChangesets: %d -> %d", from.revnum, to.revnum);
|
console.log("[revisioncache] requestChangesets: %d -> %d", from.revnum, to.revnum);
|
||||||
var delta = to.revnum - from.revnum;
|
var delta = to.revnum - from.revnum;
|
||||||
var sign = delta > 0 ? 1 : -1;
|
var sign = delta > 0 ? 1 : -1;
|
||||||
|
@ -328,18 +336,22 @@ $.Class("RevisionCache",
|
||||||
//At the moment if you request changesets from 2 -> 12, it will request at granularity 10.
|
//At the moment if you request changesets from 2 -> 12, it will request at granularity 10.
|
||||||
//Not sure if we shouldn't only request granularities > 1 when we have a strict multiple of 10,100 etc.
|
//Not sure if we shouldn't only request granularities > 1 when we have a strict multiple of 10,100 etc.
|
||||||
//This is compounded by the fact that revisions are 1 based!
|
//This is compounded by the fact that revisions are 1 based!
|
||||||
for (var g in Revision.granularities) {
|
/*
|
||||||
var granularity = Revision.granularities[g];
|
*for (var g in Revision.granularities) {
|
||||||
var num = Math.floor(adelta / granularity);
|
* var granularity = Revision.granularities[g];
|
||||||
adelta = adelta % granularity;
|
* var num = Math.floor(adelta / granularity);
|
||||||
if (num) {
|
* adelta = adelta % granularity;
|
||||||
this.loader.enqueue(start, granularity, process_received_changesets);
|
* if (num) {
|
||||||
start = start + (num * granularity);
|
* this.loader.enqueue(start, granularity, process_received_changesets);
|
||||||
}
|
* start = start + (num * granularity);
|
||||||
}
|
* }
|
||||||
if (adelta) {
|
*}
|
||||||
//Something went wrong!
|
*if (adelta) {
|
||||||
}
|
* //Something went wrong!
|
||||||
|
*}
|
||||||
|
*/
|
||||||
|
console.log(start, granularity);
|
||||||
|
this.loader.enqueue(start, Revision.granularities[granularity], process_received_changesets);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue