From 7ff7e33415d2bbcce76dad833b2424b6eec16564 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Sat, 30 Dec 2023 17:22:18 -0500 Subject: [PATCH] perf(schema): remove unnecessary lookahead in numeric subpath check --- lib/schema.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/schema.js b/lib/schema.js index 895e452a36c..8d816c3c44d 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -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'). @@ -645,7 +647,7 @@ Schema.prototype.path = function(path, obj) { } // subpaths? - return /\.\d+\.?.*$/.test(path) + return hasNumericSubpathRegex.test(path) ? getPositionalPath(this, path) : undefined; }