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.2.1 to 0.3.0

28

lib/profiler.js

@@ -28,10 +28,8 @@ const utils = require('./utils');

duration: duration == null ? 1000 : duration,
totalDocsExamined: totalDocsExamined,
level: [LEVEL_ALL, LEVEL_COLLSCAN].indexOf(level) >= 0 ?
level :
LEVEL_COLLSCAN,
totalDocsExamined,
level: [LEVEL_ALL, LEVEL_COLLSCAN].includes(level) ? level : LEVEL_COLLSCAN,
logger: logger || {
info: value => console.dir(value, {depth: null, colors: true}),
error: console.error
}
error: console.error,
},
};

@@ -51,7 +49,9 @@

const _this = this;
return function (res, next) {
const endTime = new Date();
this._collection[this.op](
this._conditions,
Object.assign({explain: true}, this.options),
{...this.options, explain: true},
(error, result) => {

@@ -66,8 +66,8 @@ if (error) {

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 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);

@@ -78,3 +78,3 @@ if (_this.options.isAlwaysShowQuery || isShowExplainResult) {

this.op,
[this._conditions, this.options]
[this._conditions, this.options],
);

@@ -81,0 +81,0 @@ }

const STAGE_COLLSCAN = 'COLLSCAN';
/**
* Search "COLLSCAN" in the explain result.
* @param {*} explainResult
* @returns {boolean}
*/
exports.isIncludeCollScanStage = explainResult => {
/*
Search "COLLSCAN" in the explain result.
@param explainResult {any}
@returns {Boolean}
*/
if (!explainResult) {

@@ -29,4 +29,4 @@ return false;

return (
exports.isIncludeCollScanStage(explainResult.executionStages) ||
exports.isIncludeCollScanStage(explainResult.allPlansExecution)
exports.isIncludeCollScanStage(explainResult.executionStages)
|| exports.isIncludeCollScanStage(explainResult.allPlansExecution)
);

@@ -46,8 +46,8 @@ }

/**
* Get totalDocsExamined in the explain result.
* @param {*} explainResult
* @returns {number}
*/
exports.getTotalDocsExamined = explainResult => {
/*
Get totalDocsExamined in the explain result.
@param explainResult {any}
@returns {Number}
*/
if (Array.isArray(explainResult)) {

@@ -54,0 +54,0 @@ let totalDocsExamined = 0;

{
"name": "mongoose-profiler",
"version": "0.2.1",
"version": "0.3.0",
"description": "A performance tuning tool for Mongoose.",

@@ -8,6 +8,6 @@ "main": "index.js",

"changelog": "node_modules/conventional-changelog-cli/cli.js -p angular",
"eslint": "./node_modules/eslint/bin/eslint.js ./",
"test": "./node_modules/jest/bin/jest.js --coverage",
"eslint": "node_modules/eslint/bin/eslint.js ./ --ignore-path .gitignore",
"test": "node_modules/jest/bin/jest.js --coverage",
"coveralls": "./node_modules/coveralls/bin/coveralls.js < ./coverage/lcov.info",
"ncu": "./node_modules/npm-check-updates/bin/ncu"
"ncu": "node_modules/npm-check-updates/bin/cli.js"
},

@@ -33,11 +33,11 @@ "files": [

"devDependencies": {
"conventional-changelog-cli": "2.0.34",
"coveralls": "3.1.0",
"eslint": "7.1.0",
"eslint-config-xo": "0.29.1",
"eslint-config-xo-space": "0.24.0",
"jest": "26.0.1",
"mockdate": "3.0.2",
"npm-check-updates": "6.0.1"
"conventional-changelog-cli": "2.1.1",
"coveralls": "3.1.1",
"eslint": "7.32.0",
"eslint-config-xo": "0.39.0",
"eslint-config-xo-space": "0.30.0",
"jest": "26.6.3",
"mockdate": "3.0.5",
"npm-check-updates": "11.8.5"
}
}

@@ -9,4 +9,5 @@ # mongoose-profiler

It will show the [explain results](https://docs.mongodb.com/manual/reference/explain-results/) on the console when the query is slow. Such as mongodb scans all documents in the collection without index.
**Don't use it on production.**
**Don't use it on production!!**
## Installation

@@ -13,0 +14,0 @@ ```bash

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