MCPcopy
hub / github.com/apache/pouchdb / latest

Function latest

lib/index-browser.js:1431–1464  ·  view source on GitHub ↗
(rev, metadata)

Source from the content-addressed store, hash-verified

1429
1430// returns the current leaf node for a given revision
1431function latest(rev, metadata) {
1432 var toVisit = metadata.rev_tree.slice();
1433 var node;
1434 while ((node = toVisit.pop())) {
1435 var pos = node.pos;
1436 var tree = node.ids;
1437 var id = tree[0];
1438 var opts = tree[1];
1439 var branches = tree[2];
1440 var isLeaf = branches.length === 0;
1441
1442 var history = node.history ? node.history.slice() : [];
1443 history.push({id, pos, opts});
1444
1445 if (isLeaf) {
1446 for (var i = 0, len = history.length; i < len; i++) {
1447 var historyNode = history[i];
1448 var historyRev = historyNode.pos + '-' + historyNode.id;
1449
1450 if (historyRev === rev) {
1451 // return the rev of this leaf
1452 return pos + '-' + id;
1453 }
1454 }
1455 }
1456
1457 for (var j = 0, l = branches.length; j < l; j++) {
1458 toVisit.push({pos: pos + 1, ids: branches[j], history});
1459 }
1460 }
1461
1462 /* istanbul ignore next */
1463 throw new Error('Unable to resolve latest revision for id ' + metadata.id + ', rev ' + rev);
1464}
1465
1466function tryCatchInChangeListener(self, change, pending, lastSeq) {
1467 // isolate try/catches to avoid V8 deoptimizations

Callers 1

initFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…