You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by da...@apache.org on 2026/09/10 08:03:32 UTC
(jackrabbit-oak) branch trunk updated: OAK-12396 : fix countDirectChildren depth (#3114)
This is an automated email from the ASF dual-hosted git repository.
rishabhdaim pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new 263f6e508f OAK-12396 : fix countDirectChildren depth (#3114)
263f6e508f is described below
commit 263f6e508fcd7930948f07fb4562d2c388f71f9d
Author: Rishabh Kumar <ri...@gmail.com>
AuthorDate: Thu Sep 10 13:33:25 2026 +0530
OAK-12396 : fix countDirectChildren depth (#3114)
* OAK-12396 : fix countDirectChildren depth
* OAK-12396 : simplify countDirectChildren depth calculation
---------
Co-authored-by: Rishabh Kumar <di...@adobe.com>
---
oak-run/src/main/js/oak-mongo.js | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/oak-run/src/main/js/oak-mongo.js b/oak-run/src/main/js/oak-mongo.js
index cb5cd64334..3cbdbe3a1a 100644
--- a/oak-run/src/main/js/oak-mongo.js
+++ b/oak-run/src/main/js/oak-mongo.js
@@ -135,19 +135,15 @@ var oak = (function(global){
* @memberof oak
* @method countDirectChildren
* @param {string} path the path of a node.
- * @returns {number} the number of children, including all descendant nodes.
+ * @returns {number} the number of direct child nodes.
*/
api.countDirectChildren = function(path){
if (path === undefined) {
return 0;
- } else if (path != "/") {
- path = path + "/";
}
- var depth = pathDepth(path);
- var totalCount = 0;
- var count = db.nodes.count({_id: pathFilter(depth + 1, path)});
- totalCount += count;
- return totalCount;
+ var childDepth = pathDepth(path) + 1;
+ var prefix = path == "/" ? path : path + "/";
+ return db.nodes.count({_id: pathFilter(childDepth, prefix)});
};
/**