|
|
@ -1,6 +1,5 @@ |
|
|
|
const { EventEmitter } = require('events') |
|
|
|
const { EventEmitter } = require('events') |
|
|
|
const { callbackify } = require('util') |
|
|
|
const { callbackify } = require('util') |
|
|
|
const async = require('async') |
|
|
|
|
|
|
|
const Cursor = require('./cursor.js') |
|
|
|
const Cursor = require('./cursor.js') |
|
|
|
const customUtils = require('./customUtils.js') |
|
|
|
const customUtils = require('./customUtils.js') |
|
|
|
const Executor = require('./executor.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
|
|
|
|
// STEP 1: get candidates list by checking indexes from most to least frequent usecase
|
|
|
|
const docs = _getCandidates(query) |
|
|
|
const docs = _getCandidates(query) |
|
|
|
// STEP 2: remove all expired documents
|
|
|
|
// STEP 2: remove all expired documents
|
|
|
|
if (!dontExpireStaleDocs) { |
|
|
|
if (!dontExpireStaleDocs) { |
|
|
|
const expiredDocsIds = [] |
|
|
|
const expiredDocsIds = [] |
|
|
|
const ttlIndexesFieldNames = Object.keys(this.ttlIndexes) |
|
|
|
const ttlIndexesFieldNames = Object.keys(this.ttlIndexes) |
|
|
|
|
|
|
|
|
|
|
|
docs.forEach(doc => { |
|
|
|
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) |
|
|
|
else expiredDocsIds.push(doc._id) |
|
|
|
}) |
|
|
|
}) |
|
|
|
for (const _id of expiredDocsIds) { |
|
|
|
for (const _id of expiredDocsIds) { |
|
|
|
await new Promise((resolve, reject) => { |
|
|
|
await new Promise((resolve, reject) => { |
|
|
|
this._remove({ _id: _id }, {}, err => { |
|
|
|
this._remove({ _id: _id }, {}, err => { |
|
|
|
if (err) return reject(err) |
|
|
|
if (err) return reject(err) |
|
|
|
return resolve() |
|
|
|
return resolve() |
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} else validDocs.push(...docs) |
|
|
|
} else validDocs.push(...docs) |
|
|
|
return validDocs |
|
|
|
return validDocs |
|
|
|