shodaaan commented on code in PR #1514:
URL: https://github.com/apache/jackrabbit-oak/pull/1514#discussion_r1634425986


##########
oak-run/src/main/js/oak-mongo.js:
##########
@@ -573,6 +595,201 @@ var oak = (function(global){
         }
     };
 
+    /**
+     * Prtints the sizes of all revisions by property.
+     * This is useful for large documents to quickly see which property/ies 
are affected
+     *
+     * @memberof oak
+     * @method propertySizes
+     * @param {string} path the path of a document
+     * @param {number} sizeLargerThan only show properteis larger than this, 
defaults to 1
+     */
+    api.propertySizes = function(path, sizeLargerThan) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        if (sizeLargerThan == undefined) {
+            sizeLargerThan = 1;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var overall = Object.bsonsize(doc);
+        print("overall size : " + overall);
+        var k;
+        for (k in doc) {
+            if (k == "_id") {
+                continue;
+            }
+            var hasown = doc.hasOwnProperty(k)
+            var subdoc = doc[k];
+            var thetype = Object.prototype.toString.call(subdoc);
+            var isBson = (thetype == "[object BSON]");
+            if (!isBson) {
+                //print("   (not a bson, skipping " + k + ")");
+                continue;
+            }
+            var subdocsize = Object.bsonsize(subdoc);
+            if (subdocsize <= sizeLargerThan) {
+                //print("   (too small to report " + k + ")");
+                continue;
+            }
+            print(" - property " + k + " size : " + subdocsize);
+        }
+    }
+
+    /**
+     * Prtints the count of property revisions by clusterId
+     * The output is using the pseudo-revision format used elsewhere already
+     * where timestamp and count are 0 - mainly to point out the clusterId it 
belongs to
+     * This is useful for large documents to quickly see which clusterId was 
the
+     * most frequent writer.
+     *
+     * @memberof oak
+     * @method propertyClusterIdCounts
+     * @param {string} path the path of a document
+     */
+    api.propertyClusterIdCounts = function(path) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var k;
+        var stats = {};
+        for (k in doc) {
+            if (k == "_id") {
+                continue;
+            }
+            var subdoc = doc[k];
+            var r;
+            var clusterIds = undefined;
+            for (r in subdoc) {
+                if (!subdoc.hasOwnProperty(r)) {
+                    continue;
+                }
+                var v = subdoc[r];
+                var clusterId = "r0-0-" + new Revision(r).getClusterId();
+                if (clusterIds === undefined) {
+                    clusterIds = {};
+                }
+                var existing = clusterIds[clusterId];
+                if (existing === undefined) {
+                    existing = 1;
+                } else {
+                    existing++;
+                }
+                clusterIds[clusterId] = existing;
+            }
+            if (clusterIds !== undefined) {
+                stats[k] = clusterIds;
+            }
+        }
+        // pretty format the output using stringify
+        print(JSON.stringify(stats, null, 8));
+    }
+
+    /**
+     * Prtints commit value of all branch commits.
+     *
+     * @memberof oak
+     * @method branchCommitValues
+     * @param {string} path the path of a document
+     */
+    api.branchCommitValues = function(path) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var num = 0;
+        var r;

Review Comment:
   I'm assuming "r" here is "revision": renaming to "rev" or adding a comment 
would make this a bit more clear.



##########
oak-run/src/main/js/oak-mongo.js:
##########
@@ -573,6 +595,201 @@ var oak = (function(global){
         }
     };
 
+    /**
+     * Prtints the sizes of all revisions by property.
+     * This is useful for large documents to quickly see which property/ies 
are affected
+     *
+     * @memberof oak
+     * @method propertySizes
+     * @param {string} path the path of a document
+     * @param {number} sizeLargerThan only show properteis larger than this, 
defaults to 1

Review Comment:
   small typo: properteis



##########
oak-run/src/main/js/oak-mongo.js:
##########
@@ -573,6 +595,201 @@ var oak = (function(global){
         }
     };
 
+    /**
+     * Prtints the sizes of all revisions by property.
+     * This is useful for large documents to quickly see which property/ies 
are affected
+     *
+     * @memberof oak
+     * @method propertySizes
+     * @param {string} path the path of a document
+     * @param {number} sizeLargerThan only show properteis larger than this, 
defaults to 1
+     */
+    api.propertySizes = function(path, sizeLargerThan) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        if (sizeLargerThan == undefined) {
+            sizeLargerThan = 1;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var overall = Object.bsonsize(doc);
+        print("overall size : " + overall);
+        var k;
+        for (k in doc) {
+            if (k == "_id") {
+                continue;
+            }
+            var hasown = doc.hasOwnProperty(k)
+            var subdoc = doc[k];
+            var thetype = Object.prototype.toString.call(subdoc);
+            var isBson = (thetype == "[object BSON]");
+            if (!isBson) {
+                //print("   (not a bson, skipping " + k + ")");
+                continue;
+            }
+            var subdocsize = Object.bsonsize(subdoc);
+            if (subdocsize <= sizeLargerThan) {
+                //print("   (too small to report " + k + ")");
+                continue;
+            }
+            print(" - property " + k + " size : " + subdocsize);
+        }
+    }
+
+    /**
+     * Prtints the count of property revisions by clusterId
+     * The output is using the pseudo-revision format used elsewhere already
+     * where timestamp and count are 0 - mainly to point out the clusterId it 
belongs to
+     * This is useful for large documents to quickly see which clusterId was 
the
+     * most frequent writer.
+     *
+     * @memberof oak
+     * @method propertyClusterIdCounts
+     * @param {string} path the path of a document
+     */
+    api.propertyClusterIdCounts = function(path) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var k;
+        var stats = {};
+        for (k in doc) {

Review Comment:
   Same here: "prop" instead of "k" would make it more clear.



##########
oak-run/src/main/js/oak-mongo.js:
##########
@@ -128,6 +128,28 @@ var oak = (function(global){
         return totalCount;
     };
 
+    /**
+     * Determines the number of direct child node (excluding any sub tree)
+     * for a given parent node path.
+     *
+     * @memberof oak
+     * @method countDirectChildren
+     * @param {string} path the path of a node.
+     * @returns {number} the number of children, including all descendant 
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++, path)});

Review Comment:
   Using depth + 1 instead of depth++ might be a bit more clear.



##########
oak-run/src/main/js/oak-mongo.js:
##########
@@ -573,6 +595,201 @@ var oak = (function(global){
         }
     };
 
+    /**
+     * Prtints the sizes of all revisions by property.
+     * This is useful for large documents to quickly see which property/ies 
are affected
+     *
+     * @memberof oak
+     * @method propertySizes
+     * @param {string} path the path of a document
+     * @param {number} sizeLargerThan only show properteis larger than this, 
defaults to 1
+     */
+    api.propertySizes = function(path, sizeLargerThan) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        if (sizeLargerThan == undefined) {
+            sizeLargerThan = 1;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var overall = Object.bsonsize(doc);
+        print("overall size : " + overall);
+        var k;
+        for (k in doc) {
+            if (k == "_id") {
+                continue;
+            }
+            var hasown = doc.hasOwnProperty(k)
+            var subdoc = doc[k];
+            var thetype = Object.prototype.toString.call(subdoc);
+            var isBson = (thetype == "[object BSON]");
+            if (!isBson) {
+                //print("   (not a bson, skipping " + k + ")");
+                continue;
+            }
+            var subdocsize = Object.bsonsize(subdoc);
+            if (subdocsize <= sizeLargerThan) {
+                //print("   (too small to report " + k + ")");
+                continue;
+            }
+            print(" - property " + k + " size : " + subdocsize);
+        }
+    }
+
+    /**
+     * Prtints the count of property revisions by clusterId
+     * The output is using the pseudo-revision format used elsewhere already
+     * where timestamp and count are 0 - mainly to point out the clusterId it 
belongs to
+     * This is useful for large documents to quickly see which clusterId was 
the
+     * most frequent writer.
+     *
+     * @memberof oak
+     * @method propertyClusterIdCounts
+     * @param {string} path the path of a document
+     */
+    api.propertyClusterIdCounts = function(path) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var k;
+        var stats = {};
+        for (k in doc) {
+            if (k == "_id") {
+                continue;
+            }
+            var subdoc = doc[k];
+            var r;
+            var clusterIds = undefined;
+            for (r in subdoc) {
+                if (!subdoc.hasOwnProperty(r)) {
+                    continue;
+                }
+                var v = subdoc[r];
+                var clusterId = "r0-0-" + new Revision(r).getClusterId();
+                if (clusterIds === undefined) {
+                    clusterIds = {};
+                }
+                var existing = clusterIds[clusterId];
+                if (existing === undefined) {
+                    existing = 1;
+                } else {
+                    existing++;
+                }
+                clusterIds[clusterId] = existing;
+            }
+            if (clusterIds !== undefined) {
+                stats[k] = clusterIds;
+            }
+        }
+        // pretty format the output using stringify
+        print(JSON.stringify(stats, null, 8));
+    }
+
+    /**
+     * Prtints commit value of all branch commits.
+     *
+     * @memberof oak
+     * @method branchCommitValues
+     * @param {string} path the path of a document
+     */
+    api.branchCommitValues = function(path) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var num = 0;
+        var r;
+        var cachedRoot = this.findOne("/");
+        for (r in doc._bc) {
+            var commitValue = this.getCommitValue("/", r, cachedRoot)
+            if (commitValue && commitValue[r] && 
commitValue[r].startsWith("c-")) {
+                print(" - branch change " + r + " is committed");
+                continue;
+            }
+            print(" - branch change " + r + " is not or not yet committed");
+            num++;
+        }
+        print("Number of unmerged branch changes : " + num);
+    }
+
+    api.sizeOf = function(obj) {
+        var thetype = Object.prototype.toString.call(obj);
+        if (thetype == "[object BSON]") {
+            return Object.bsonsize(obj);
+        } else if (thetype == "[object Null]") {
+            return 0;
+        } else if (thetype == "[object String]") {
+            return obj.length;
+        }
+        print("sizeOf: obj not a bson but : " + thetype);
+        return 42;
+    }
+
+    api.unmergedBranchStatsForProperty = function(path, property) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var subdoc = doc[property];
+        var num = 0;
+        var totalGarbage  = 0;
+        var cachedRoot = this.findOne("/");
+        var propertyGarbageSizes = {};
+        var r, clusterId, clusterIdGarbage;

Review Comment:
   Renaming "r" to "rev" would make it more clear.



##########
oak-run/src/main/js/oak-mongo.js:
##########
@@ -573,6 +595,201 @@ var oak = (function(global){
         }
     };
 
+    /**
+     * Prtints the sizes of all revisions by property.
+     * This is useful for large documents to quickly see which property/ies 
are affected
+     *
+     * @memberof oak
+     * @method propertySizes
+     * @param {string} path the path of a document
+     * @param {number} sizeLargerThan only show properteis larger than this, 
defaults to 1
+     */
+    api.propertySizes = function(path, sizeLargerThan) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        if (sizeLargerThan == undefined) {
+            sizeLargerThan = 1;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var overall = Object.bsonsize(doc);
+        print("overall size : " + overall);
+        var k;
+        for (k in doc) {
+            if (k == "_id") {
+                continue;
+            }
+            var hasown = doc.hasOwnProperty(k)
+            var subdoc = doc[k];
+            var thetype = Object.prototype.toString.call(subdoc);
+            var isBson = (thetype == "[object BSON]");
+            if (!isBson) {
+                //print("   (not a bson, skipping " + k + ")");
+                continue;
+            }
+            var subdocsize = Object.bsonsize(subdoc);
+            if (subdocsize <= sizeLargerThan) {
+                //print("   (too small to report " + k + ")");
+                continue;
+            }
+            print(" - property " + k + " size : " + subdocsize);
+        }
+    }
+
+    /**
+     * Prtints the count of property revisions by clusterId
+     * The output is using the pseudo-revision format used elsewhere already
+     * where timestamp and count are 0 - mainly to point out the clusterId it 
belongs to
+     * This is useful for large documents to quickly see which clusterId was 
the
+     * most frequent writer.
+     *
+     * @memberof oak
+     * @method propertyClusterIdCounts
+     * @param {string} path the path of a document
+     */
+    api.propertyClusterIdCounts = function(path) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var k;
+        var stats = {};
+        for (k in doc) {
+            if (k == "_id") {
+                continue;
+            }
+            var subdoc = doc[k];
+            var r;
+            var clusterIds = undefined;
+            for (r in subdoc) {
+                if (!subdoc.hasOwnProperty(r)) {
+                    continue;
+                }
+                var v = subdoc[r];
+                var clusterId = "r0-0-" + new Revision(r).getClusterId();
+                if (clusterIds === undefined) {
+                    clusterIds = {};
+                }
+                var existing = clusterIds[clusterId];
+                if (existing === undefined) {
+                    existing = 1;
+                } else {
+                    existing++;
+                }
+                clusterIds[clusterId] = existing;
+            }
+            if (clusterIds !== undefined) {
+                stats[k] = clusterIds;
+            }
+        }
+        // pretty format the output using stringify
+        print(JSON.stringify(stats, null, 8));
+    }
+
+    /**
+     * Prtints commit value of all branch commits.
+     *
+     * @memberof oak
+     * @method branchCommitValues
+     * @param {string} path the path of a document
+     */
+    api.branchCommitValues = function(path) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var num = 0;
+        var r;
+        var cachedRoot = this.findOne("/");
+        for (r in doc._bc) {
+            var commitValue = this.getCommitValue("/", r, cachedRoot)
+            if (commitValue && commitValue[r] && 
commitValue[r].startsWith("c-")) {
+                print(" - branch change " + r + " is committed");
+                continue;
+            }
+            print(" - branch change " + r + " is not or not yet committed");
+            num++;
+        }
+        print("Number of unmerged branch changes : " + num);
+    }
+
+    api.sizeOf = function(obj) {
+        var thetype = Object.prototype.toString.call(obj);
+        if (thetype == "[object BSON]") {
+            return Object.bsonsize(obj);
+        } else if (thetype == "[object Null]") {
+            return 0;
+        } else if (thetype == "[object String]") {
+            return obj.length;
+        }
+        print("sizeOf: obj not a bson but : " + thetype);
+        return 42;
+    }
+
+    api.unmergedBranchStatsForProperty = function(path, property) {

Review Comment:
   Please consider adding a short description for what this method does.



##########
oak-run/src/main/js/oak-mongo.js:
##########
@@ -573,6 +595,201 @@ var oak = (function(global){
         }
     };
 
+    /**
+     * Prtints the sizes of all revisions by property.
+     * This is useful for large documents to quickly see which property/ies 
are affected
+     *
+     * @memberof oak
+     * @method propertySizes
+     * @param {string} path the path of a document
+     * @param {number} sizeLargerThan only show properteis larger than this, 
defaults to 1
+     */
+    api.propertySizes = function(path, sizeLargerThan) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        if (sizeLargerThan == undefined) {
+            sizeLargerThan = 1;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var overall = Object.bsonsize(doc);
+        print("overall size : " + overall);
+        var k;

Review Comment:
   Renaming k to "prop" might make this a bit more clear.



##########
oak-run/src/main/js/oak-mongo.js:
##########
@@ -573,6 +595,201 @@ var oak = (function(global){
         }
     };
 
+    /**
+     * Prtints the sizes of all revisions by property.
+     * This is useful for large documents to quickly see which property/ies 
are affected
+     *
+     * @memberof oak
+     * @method propertySizes
+     * @param {string} path the path of a document
+     * @param {number} sizeLargerThan only show properteis larger than this, 
defaults to 1
+     */
+    api.propertySizes = function(path, sizeLargerThan) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        if (sizeLargerThan == undefined) {
+            sizeLargerThan = 1;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var overall = Object.bsonsize(doc);
+        print("overall size : " + overall);
+        var k;
+        for (k in doc) {
+            if (k == "_id") {
+                continue;
+            }
+            var hasown = doc.hasOwnProperty(k)
+            var subdoc = doc[k];
+            var thetype = Object.prototype.toString.call(subdoc);
+            var isBson = (thetype == "[object BSON]");
+            if (!isBson) {
+                //print("   (not a bson, skipping " + k + ")");
+                continue;
+            }
+            var subdocsize = Object.bsonsize(subdoc);
+            if (subdocsize <= sizeLargerThan) {
+                //print("   (too small to report " + k + ")");
+                continue;
+            }
+            print(" - property " + k + " size : " + subdocsize);
+        }
+    }
+
+    /**
+     * Prtints the count of property revisions by clusterId

Review Comment:
   Prtints - should this be "Prints" or is it something else?



##########
oak-run/src/main/js/oak-mongo.js:
##########
@@ -573,6 +595,201 @@ var oak = (function(global){
         }
     };
 
+    /**
+     * Prtints the sizes of all revisions by property.
+     * This is useful for large documents to quickly see which property/ies 
are affected
+     *
+     * @memberof oak
+     * @method propertySizes
+     * @param {string} path the path of a document
+     * @param {number} sizeLargerThan only show properteis larger than this, 
defaults to 1
+     */
+    api.propertySizes = function(path, sizeLargerThan) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        if (sizeLargerThan == undefined) {
+            sizeLargerThan = 1;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var overall = Object.bsonsize(doc);
+        print("overall size : " + overall);
+        var k;
+        for (k in doc) {
+            if (k == "_id") {
+                continue;
+            }
+            var hasown = doc.hasOwnProperty(k)
+            var subdoc = doc[k];
+            var thetype = Object.prototype.toString.call(subdoc);
+            var isBson = (thetype == "[object BSON]");
+            if (!isBson) {
+                //print("   (not a bson, skipping " + k + ")");
+                continue;
+            }
+            var subdocsize = Object.bsonsize(subdoc);
+            if (subdocsize <= sizeLargerThan) {
+                //print("   (too small to report " + k + ")");
+                continue;
+            }
+            print(" - property " + k + " size : " + subdocsize);
+        }
+    }
+
+    /**
+     * Prtints the count of property revisions by clusterId
+     * The output is using the pseudo-revision format used elsewhere already
+     * where timestamp and count are 0 - mainly to point out the clusterId it 
belongs to
+     * This is useful for large documents to quickly see which clusterId was 
the
+     * most frequent writer.
+     *
+     * @memberof oak
+     * @method propertyClusterIdCounts
+     * @param {string} path the path of a document
+     */
+    api.propertyClusterIdCounts = function(path) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var k;
+        var stats = {};
+        for (k in doc) {
+            if (k == "_id") {
+                continue;
+            }
+            var subdoc = doc[k];
+            var r;
+            var clusterIds = undefined;
+            for (r in subdoc) {
+                if (!subdoc.hasOwnProperty(r)) {
+                    continue;
+                }
+                var v = subdoc[r];
+                var clusterId = "r0-0-" + new Revision(r).getClusterId();
+                if (clusterIds === undefined) {
+                    clusterIds = {};
+                }
+                var existing = clusterIds[clusterId];
+                if (existing === undefined) {
+                    existing = 1;
+                } else {
+                    existing++;
+                }
+                clusterIds[clusterId] = existing;
+            }
+            if (clusterIds !== undefined) {
+                stats[k] = clusterIds;
+            }
+        }
+        // pretty format the output using stringify
+        print(JSON.stringify(stats, null, 8));
+    }
+
+    /**
+     * Prtints commit value of all branch commits.
+     *
+     * @memberof oak
+     * @method branchCommitValues
+     * @param {string} path the path of a document
+     */
+    api.branchCommitValues = function(path) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        print("loading document at " + path);
+        var doc = this.findOne(path);
+        if (!doc) {
+            print("No document for path: " + path);
+            return;
+        }
+        var num = 0;
+        var r;
+        var cachedRoot = this.findOne("/");
+        for (r in doc._bc) {
+            var commitValue = this.getCommitValue("/", r, cachedRoot)
+            if (commitValue && commitValue[r] && 
commitValue[r].startsWith("c-")) {
+                print(" - branch change " + r + " is committed");
+                continue;
+            }
+            print(" - branch change " + r + " is not or not yet committed");
+            num++;
+        }
+        print("Number of unmerged branch changes : " + num);
+    }
+
+    api.sizeOf = function(obj) {

Review Comment:
   Please consider adding a short description for what this method does.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to