Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-profiler

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-profiler - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

63

lib/profiler.js

@@ -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"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc