Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
txn.get(stores.docStore, docId, function (err, metadata) {
/* istanbul ignore if */
if (err) {
return callback(err)
}
var seqs = revs.map(function (rev) {
var seq = metadata.rev_map[rev]
delete metadata.rev_map[rev]
return seq
})
traverseRevTree(metadata.rev_tree, function (isLeaf, pos, revHash, ctx, opts) {
var rev = pos + '-' + revHash
if (revs.indexOf(rev) !== -1) {
opts.status = 'missing'
}
})
var batch = []
batch.push({
key: metadata.id,
value: metadata,
type: 'put',
prefix: stores.docStore
})
var digestMap = {}
var numDone = 0
function processDoc(id, rev_tree) {
// Is this fast enough? Maybe we should switch to a set simulated by a map
var missingForId = req[id].slice(0);
traverseRevTree(rev_tree, function (isLeaf, pos, revHash, ctx,
opts) {
var rev = pos + '-' + revHash;
var idx = missingForId.indexOf(rev);
if (idx === -1) {
return;
}
missingForId.splice(idx, 1);
/* istanbul ignore if */
if (opts.status !== 'available') {
addToMissing(id, rev);
}
});
// Traversing the tree is synchronous, so now `missingForId` contains
// revisions that were not found in the tree
txn.get(stores.docStore, docId, function (err, metadata) {
/* istanbul ignore if */
if (err) {
return callback(err);
}
var seqs = revs.map(function (rev) {
var seq = metadata.rev_map[rev];
delete metadata.rev_map[rev];
return seq;
});
traverseRevTree(metadata.rev_tree, function (isLeaf, pos,
revHash, ctx, opts) {
var rev = pos + '-' + revHash;
if (revs.indexOf(rev) !== -1) {
opts.status = 'missing';
}
});
var batch = [];
batch.push({
key: metadata.id,
value: metadata,
type: 'put',
prefix: stores.docStore
});
var digestMap = {};
txn.get(stores.docStore, docId, function (err, metadata) {
/* istanbul ignore if */
if (err) {
return callback(err);
}
var seqs = revs.map(function (rev) {
var seq = metadata.rev_map[rev];
delete metadata.rev_map[rev];
return seq;
});
traverseRevTree(metadata.rev_tree, function (isLeaf, pos,
revHash, ctx, opts) {
var rev = pos + '-' + revHash;
if (revs.indexOf(rev) !== -1) {
opts.status = 'missing';
}
});
var batch = [];
batch.push({
key: metadata.id,
value: metadata,
type: 'put',
prefix: stores.docStore
});
var digestMap = {};
this._getRevisionTree(docId, function (err, revTree) {
/* istanbul ignore if */
if (err) {
return callback(err);
}
var height = computeHeight(revTree);
var candidates = [];
var revs = [];
Object.keys(height).forEach(function (rev) {
if (height[rev] > maxHeight) {
candidates.push(rev);
}
});
traverseRevTree(revTree, function (isLeaf, pos, revHash, ctx, opts) {
var rev = pos + '-' + revHash;
if (opts.status === 'available' && candidates.indexOf(rev) !== -1) {
revs.push(rev);
}
});
self._doCompaction(docId, revs, callback);
});
});
function processDoc(id, rev_tree) {
// Is this fast enough? Maybe we should switch to a set simulated by a map
var missingForId = req[id].slice(0);
traverseRevTree(rev_tree, function (isLeaf, pos, revHash, ctx,
opts) {
var rev = pos + '-' + revHash;
var idx = missingForId.indexOf(rev);
if (idx === -1) {
return;
}
missingForId.splice(idx, 1);
/* istanbul ignore if */
if (opts.status !== 'available') {
addToMissing(id, rev);
}
});
// Traversing the tree is synchronous, so now `missingForId` contains
// revisions that were not found in the tree
txn.get(stores.docStore, docId, function (err, metadata) {
/* istanbul ignore if */
if (err) {
return callback(err);
}
var seqs = revs.map(function (rev) {
var seq = metadata.rev_map[rev];
delete metadata.rev_map[rev];
return seq;
});
pouchdbMerge.traverseRevTree(metadata.rev_tree, function (isLeaf, pos,
revHash, ctx, opts) {
var rev = pos + '-' + revHash;
if (revs.indexOf(rev) !== -1) {
opts.status = 'missing';
}
});
var batch = [];
batch.push({
key: metadata.id,
value: metadata,
type: 'put',
prefix: stores.docStore
});
var digestMap = {};
this._getRevisionTree(docId, function (err, revTree) {
/* istanbul ignore if */
if (err) {
return callback(err);
}
var height = computeHeight(revTree);
var candidates = [];
var revs = [];
Object.keys(height).forEach(function (rev) {
if (height[rev] > maxHeight) {
candidates.push(rev);
}
});
traverseRevTree(revTree, function (isLeaf, pos, revHash, ctx, opts) {
var rev = pos + '-' + revHash;
if (opts.status === 'available' && candidates.indexOf(rev) !== -1) {
revs.push(rev);
}
});
self._doCompaction(docId, revs, callback);
});
});
function computeHeight(revs) {
var height = {};
var edges = [];
traverseRevTree(revs, function (isLeaf, pos, id, prnt) {
var rev = pos + "-" + id;
if (isLeaf) {
height[rev] = 0;
}
if (prnt !== undefined) {
edges.push({from: prnt, to: rev});
}
return rev;
});
edges.reverse();
edges.forEach(function (edge) {
if (height[edge.from] === undefined) {
height[edge.from] = 1 + height[edge.to];
} else {
height[edge.from] = Math.min(height[edge.from], 1 + height[edge.to]);
tx.executeSql(sql, [docId], function (tx, result) {
var metadata = safeJsonParse(result.rows.item(0).metadata);
traverseRevTree(metadata.rev_tree, function (isLeaf, pos,
revHash, ctx, opts) {
var rev = pos + '-' + revHash;
if (revs.indexOf(rev) !== -1) {
opts.status = 'missing';
}
});
var sql = 'UPDATE ' + DOC_STORE + ' SET json = ? WHERE id = ?';
tx.executeSql(sql, [safeJsonStringify(metadata), docId]);
});