Skip to content

Commit 9f01e63

Browse files
authored
adapter: simplify compareByIdThenRev() (#8787)
1 parent 99f20e5 commit 9f01e63

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

packages/node_modules/pouchdb-core/src/adapter.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ import {
4040
* A generic pouch adapter
4141
*/
4242

43-
function compare(left, right) {
44-
return left < right ? -1 : left > right ? 1 : 0;
45-
}
46-
4743
// Wrapper for functions that call the bulkdocs api with a single doc,
4844
// if the first result is an error, return an error
4945
function yankError(callback, docId) {
@@ -78,13 +74,12 @@ function cleanDocs(docs) {
7874

7975
// compare two docs, first by _id then by _rev
8076
function compareByIdThenRev(a, b) {
81-
var idCompare = compare(a._id, b._id);
82-
if (idCompare !== 0) {
83-
return idCompare;
77+
if (a._id === b._id) {
78+
const aStart = a._revisions ? a._revisions.start : 0;
79+
const bStart = b._revisions ? b._revisions.start : 0;
80+
return aStart - bStart;
8481
}
85-
var aStart = a._revisions ? a._revisions.start : 0;
86-
var bStart = b._revisions ? b._revisions.start : 0;
87-
return compare(aStart, bStart);
82+
return a._id < b._id ? -1 : 1;
8883
}
8984

9085
// for every node in a revision tree computes its distance from the closest

0 commit comments

Comments
 (0)