Skip to content

Commit e69fe21

Browse files
authored
chore(PouchDB-find): minor cleanup (#8920)
* whitespace cleanup * return of query-planner/planQuery
1 parent 9ba277b commit e69fe21

File tree

4 files changed

+14
-30
lines changed

4 files changed

+14
-30
lines changed

packages/node_modules/pouchdb-find/src/adapters/local/find/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {clone} from 'pouchdb-utils';
1+
import { clone } from 'pouchdb-utils';
22
import getIndexes from '../get-indexes';
3-
import {collate} from 'pouchdb-collate';
3+
import { collate } from 'pouchdb-collate';
44
import abstractMapper from '../abstract-mapper';
55
import planQuery from './query-planner';
66
import {
@@ -16,7 +16,7 @@ import {
1616
filterInclusiveStart,
1717
massageUseIndex
1818
} from '../utils';
19-
import {pick} from '../../../utils';
19+
import { pick } from '../../../utils';
2020
import validateSelector from '../../../validateSelector';
2121

2222
function indexToSignature(index) {
@@ -112,10 +112,10 @@ async function find(db, requestDef, explain) {
112112
}, queryPlan.queryOpts);
113113

114114
if ('startkey' in opts && 'endkey' in opts &&
115-
collate(opts.startkey, opts.endkey) > 0) {
115+
collate(opts.startkey, opts.endkey) > 0) {
116116
// can't possibly return any results, startkey > endkey
117117
/* istanbul ignore next */
118-
return {docs: []};
118+
return { docs: [] };
119119
}
120120

121121
const isDescending = requestDef.sort &&

packages/node_modules/pouchdb-find/src/adapters/local/find/query-planner.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ function sortFieldsByIndex(userFields, index) {
6767

6868
// first pass to try to find fields that will need to be sorted in-memory
6969
function getBasicInMemoryFields(index, selector, userFields) {
70-
7170
userFields = sortFieldsByIndex(userFields, index);
7271

7372
// check if any of the user selectors lose precision
@@ -152,9 +151,7 @@ function checkFieldsLogicallySound(indexFields, selector) {
152151
}
153152

154153
function checkIndexMatches(index, sortOrder, fields, selector) {
155-
156154
const indexFields = index.def.fields.map(getKey);
157-
158155
const fieldsMatch = checkIndexFieldsMatch(indexFields, sortOrder, fields);
159156

160157
if (!fieldsMatch) {
@@ -170,7 +167,6 @@ function checkIndexMatches(index, sortOrder, fields, selector) {
170167
// are a strict subset of the fields in some index,
171168
// then use that index
172169
//
173-
//
174170
function findMatchingIndexes(selector, userFields, sortOrder, indexes) {
175171
return indexes.filter(function (index) {
176172
return checkIndexMatches(index, sortOrder, userFields, selector);
@@ -180,7 +176,6 @@ function findMatchingIndexes(selector, userFields, sortOrder, indexes) {
180176
// find the best index, i.e. the one that matches the most fields
181177
// in the user's query
182178
function findBestMatchingIndex(selector, userFields, sortOrder, indexes, useIndex) {
183-
184179
const matchingIndexes = findMatchingIndexes(selector, userFields, sortOrder, indexes);
185180

186181
if (matchingIndexes.length === 0) {
@@ -190,8 +185,8 @@ function findBestMatchingIndex(selector, userFields, sortOrder, indexes, useInde
190185
message: "There is no index available for this selector."
191186
};
192187
}
193-
//return `all_docs` as a default index;
194-
//I'm assuming that _all_docs is always first
188+
// return `all_docs` as a default index;
189+
// I'm assuming that _all_docs is always first
195190
const defaultIndex = indexes[0];
196191
defaultIndex.defaultUsed = true;
197192
return defaultIndex;
@@ -244,11 +239,11 @@ function findBestMatchingIndex(selector, userFields, sortOrder, indexes, useInde
244239
function getSingleFieldQueryOptsFor(userOperator, userValue) {
245240
switch (userOperator) {
246241
case '$eq':
247-
return {key: userValue};
242+
return { key: userValue };
248243
case '$lte':
249-
return {endkey: userValue};
244+
return { endkey: userValue };
250245
case '$gte':
251-
return {startkey: userValue};
246+
return { startkey: userValue };
252247
case '$lt':
253248
return {
254249
endkey: userValue,
@@ -272,7 +267,6 @@ function getSingleFieldCoreQueryPlan(selector, index) {
272267
/* istanbul ignore next */
273268
const matcher = selector[field] || {};
274269
const inMemoryFields = [];
275-
276270
const userOperators = Object.keys(matcher);
277271

278272
let combinedOpts;
@@ -283,7 +277,6 @@ function getSingleFieldCoreQueryPlan(selector, index) {
283277
}
284278

285279
const userValue = matcher[userOperator];
286-
287280
const newQueryOpts = getSingleFieldQueryOptsFor(userOperator, userValue);
288281

289282
if (combinedOpts) {
@@ -328,7 +321,6 @@ function getMultiFieldCoreQueryPlan(userOperator, userValue) {
328321
}
329322

330323
function getMultiFieldQueryOpts(selector, index) {
331-
332324
const indexFields = index.def.fields.map(getKey);
333325

334326
let inMemoryFields = [];
@@ -337,7 +329,6 @@ function getMultiFieldQueryOpts(selector, index) {
337329
let inclusiveStart;
338330
let inclusiveEnd;
339331

340-
341332
function finish(i) {
342333

343334
if (inclusiveStart !== false) {
@@ -353,7 +344,6 @@ function getMultiFieldQueryOpts(selector, index) {
353344

354345
for (let i = 0, len = indexFields.length; i < len; i++) {
355346
const indexField = indexFields[i];
356-
357347
const matcher = selector[indexField];
358348

359349
if (!matcher || !Object.keys(matcher).length) { // fewer fields in user query than in index
@@ -377,12 +367,10 @@ function getMultiFieldQueryOpts(selector, index) {
377367
}
378368

379369
const userOperators = Object.keys(matcher);
380-
381370
let combinedOpts = null;
382371

383372
for (const userOperator of userOperators) {
384373
const userValue = matcher[userOperator];
385-
386374
const newOpts = getMultiFieldCoreQueryPlan(userOperator, userValue);
387375

388376
if (combinedOpts) {
@@ -432,13 +420,13 @@ function shouldShortCircuit(selector) {
432420
});
433421
return values.some(function (val) {
434422
return typeof val === 'object' && Object.keys(val).length === 0;
435-
});
423+
});
436424
}
437425

438426
function getDefaultQueryPlan(selector) {
439427
//using default index, so all fields need to be done in memory
440428
return {
441-
queryOpts: {startkey: null},
429+
queryOpts: { startkey: null },
442430
inMemoryFields: [Object.keys(selector)]
443431
};
444432
}
@@ -457,7 +445,6 @@ function getCoreQueryPlan(selector, index) {
457445
}
458446

459447
function planQuery(request, indexes) {
460-
461448
const selector = request.selector;
462449
const sort = request.sort;
463450

@@ -477,12 +464,11 @@ function planQuery(request, indexes) {
477464

478465
const inMemoryFields = getInMemoryFields(coreInMemoryFields, index, selector, userFields);
479466

480-
const res = {
467+
return {
481468
queryOpts,
482469
index,
483470
inMemoryFields
484471
};
485-
return res;
486472
}
487473

488474
export default planQuery;

packages/node_modules/pouchdb-find/src/adapters/local/get-indexes/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function getIndexes(db) {
1616
name: '_all_docs',
1717
type: 'special',
1818
def: {
19-
fields: [{_id: 'asc'}]
19+
fields: [{ _id: 'asc' }]
2020
}
2121
}]
2222
};

packages/node_modules/pouchdb-find/src/utils.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ function pick(obj, arr) {
128128

129129
// e.g. ['a'], ['a', 'b'] is true, but ['b'], ['a', 'b'] is false
130130
function oneArrayIsSubArrayOfOther(left, right) {
131-
132131
for (let i = 0, len = Math.min(left.length, right.length); i < len; i++) {
133132
if (left[i] !== right[i]) {
134133
return false;
@@ -139,7 +138,6 @@ function oneArrayIsSubArrayOfOther(left, right) {
139138

140139
// e.g.['a', 'b', 'c'], ['a', 'b'] is false
141140
function oneArrayIsStrictSubArrayOfOther(left, right) {
142-
143141
if (left.length > right.length) {
144142
return false;
145143
}

0 commit comments

Comments
 (0)