WIP: linting

pull/11/head
Timothée Rebours 3 years ago
parent f9e4c525e4
commit 5f7bc1244d
  1. 17
      lib/datastore.js

@ -1,6 +1,5 @@
const { EventEmitter } = require('events')
const { callbackify } = require('util')
const async = require('async')
const Cursor = require('./cursor.js')
const customUtils = require('./customUtils.js')
const Executor = require('./executor.js')
@ -315,21 +314,21 @@ class Datastore extends EventEmitter {
// STEP 1: get candidates list by checking indexes from most to least frequent usecase
const docs = _getCandidates(query)
// STEP 2: remove all expired documents
if (!dontExpireStaleDocs) {
if (!dontExpireStaleDocs) {
const expiredDocsIds = []
const ttlIndexesFieldNames = Object.keys(this.ttlIndexes)
docs.forEach(doc => {
if (ttlIndexesFieldNames.every(i => !(doc[i] !== undefined && isDate(doc[i]) && Date.now() > doc[i].getTime() + this.ttlIndexes[i] * 1000))) validDocs.push(doc)
if (ttlIndexesFieldNames.every(i => !(doc[i] !== undefined && isDate(doc[i]) && Date.now() > doc[i].getTime() + this.ttlIndexes[i] * 1000))) validDocs.push(doc)
else expiredDocsIds.push(doc._id)
})
for (const _id of expiredDocsIds) {
await new Promise((resolve, reject) => {
this._remove({ _id: _id }, {}, err => {
if (err) return reject(err)
return resolve()
})
for (const _id of expiredDocsIds) {
await new Promise((resolve, reject) => {
this._remove({ _id: _id }, {}, err => {
if (err) return reject(err)
return resolve()
})
})
}
} else validDocs.push(...docs)
return validDocs

Loading…
Cancel
Save