mongoose-profiler
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -15,3 +15,3 @@ const utils = require('./utils'); | ||
* Show the explain result when the query examined documents more than this number. | ||
* "null" is disable this function. | ||
* "null" is disabled this function. | ||
* @param {string} level - "ALL|COLLSCAN" | ||
@@ -50,39 +50,36 @@ * The default is COLLSCAN. | ||
return function (res, next) { | ||
const endTime = new Date(); | ||
return async function () { | ||
try { | ||
const endTime = new Date(); | ||
const result = await this._collection[this.op]( | ||
this._conditions, | ||
{...this.options, explain: true}, | ||
); | ||
this._collection[this.op]( | ||
this._conditions, | ||
{...this.options, explain: true}, | ||
(error, result) => { | ||
if (error) { | ||
_this.options.logger.error(error); | ||
return; | ||
} | ||
const processTime = `${endTime - this.startTime}`.replace(/\B(?=(\d{3})+(?!\d))/g, ','); | ||
const isIncludeCollScanStage = utils.isIncludeCollScanStage(result); | ||
const isOverDuration = (endTime - this.startTime) > _this.options.duration; | ||
const isOverTotalDocsExamined = _this.options.totalDocsExamined == null | ||
? false | ||
: utils.getTotalDocsExamined(result) > _this.options.totalDocsExamined; | ||
const isShowExplainResult = isOverDuration || isOverTotalDocsExamined | ||
|| _this.options.level === LEVEL_ALL | ||
|| (_this.options.level === LEVEL_COLLSCAN && isIncludeCollScanStage); | ||
const processTime = `${endTime - this.startTime}`.replace(/\B(?=(\d{3})+(?!\d))/g, ','); | ||
const isIncludeCollScanStage = utils.isIncludeCollScanStage(result); | ||
const isOverDuration = (endTime - this.startTime) > _this.options.duration; | ||
const isOverTotalDocsExamined = _this.options.totalDocsExamined == null | ||
? false | ||
: utils.getTotalDocsExamined(result) > _this.options.totalDocsExamined; | ||
const isShowExplainResult = isOverDuration || isOverTotalDocsExamined | ||
|| _this.options.level === LEVEL_ALL | ||
|| (_this.options.level === LEVEL_COLLSCAN && isIncludeCollScanStage); | ||
if (_this.options.isAlwaysShowQuery || isShowExplainResult) { | ||
this.mongooseCollection.$print( | ||
`${processTime.padStart(7)}ms ${this.mongooseCollection.collectionName}`, | ||
this.op, | ||
[this._conditions, this.options], | ||
); | ||
} | ||
if (_this.options.isAlwaysShowQuery || isShowExplainResult) { | ||
this.mongooseCollection.$print( | ||
`${processTime.padStart(7)}ms ${this.mongooseCollection.collectionName}`, | ||
this.op, | ||
[this._conditions, this.options], | ||
); | ||
} | ||
if (isShowExplainResult) { | ||
_this.options.logger.info(result); | ||
} | ||
}); | ||
next(); | ||
if (isShowExplainResult) { | ||
_this.options.logger.info(result); | ||
} | ||
} catch (error) { | ||
_this.options.logger.error(error); | ||
} | ||
}; | ||
} | ||
}; |
{ | ||
"name": "mongoose-profiler", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A performance tuning tool for Mongoose.", | ||
@@ -34,6 +34,6 @@ "main": "index.js", | ||
"coveralls": "3.1.1", | ||
"eslint": "7.32.0", | ||
"eslint": "8.6.0", | ||
"eslint-config-xo": "0.39.0", | ||
"eslint-config-xo-space": "0.30.0", | ||
"jest": "26.6.3", | ||
"jest": "27.4.5", | ||
"mockdate": "3.0.5", | ||
@@ -40,0 +40,0 @@ "npm-check-updates": "11.8.5" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11903
134