Skip to content

Commit

Permalink
perf(schema): remove unnecessary lookahead in numeric subpath check
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Dec 30, 2023
1 parent 09c55b3 commit 7ff7e33
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const util = require('util');
const utils = require('./utils');
const validateRef = require('./helpers/populate/validateRef');

const hasNumericSubpathRegex = /\.\d+(\.|$)/;

let MongooseTypes;

const queryHooks = require('./helpers/query/applyQueryMiddleware').
Expand Down Expand Up @@ -645,7 +647,7 @@ Schema.prototype.path = function(path, obj) {
}

// subpaths?
return /\.\d+\.?.*$/.test(path)
return hasNumericSubpathRegex.test(path)
? getPositionalPath(this, path)
: undefined;
}
Expand Down

0 comments on commit 7ff7e33

Please sign in to comment.