@@ -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
6969function 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
154153function 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- //
174170function 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
182178function 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
244239function 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
330323function 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
438426function 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
459447function 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
488474export default planQuery ;
0 commit comments