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 jo...@apache.org on 2024/05/13 15:47:15 UTC
(jackrabbit-oak) branch OAK-10801 created (now a1999ab8e9)
This is an automated email from the ASF dual-hosted git repository.
joscorbe pushed a change to branch OAK-10801
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
at a1999ab8e9 OAK-10801: Introduce functions to remove nodes that are older than a timestamp
This branch includes the following new commits:
new a1999ab8e9 OAK-10801: Introduce functions to remove nodes that are older than a timestamp
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(jackrabbit-oak) 01/01: OAK-10801: Introduce functions to remove nodes that are older than a timestamp
Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
joscorbe pushed a commit to branch OAK-10801
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit a1999ab8e90e536c265ff9bae11a75bbdb1381d4
Author: Jose Cordero <co...@adobe.com>
AuthorDate: Mon May 13 17:46:54 2024 +0200
OAK-10801: Introduce functions to remove nodes that are older than a timestamp
---
oak-run/src/main/js/oak-mongo.js | 49 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)
diff --git a/oak-run/src/main/js/oak-mongo.js b/oak-run/src/main/js/oak-mongo.js
index 8f8d264e7e..605dff87e0 100644
--- a/oak-run/src/main/js/oak-mongo.js
+++ b/oak-run/src/main/js/oak-mongo.js
@@ -329,6 +329,53 @@ var oak = (function(global){
return {nRemoved : count};
};
+ /**
+ * Finds all the descendants with a _modified timestamp older than the
+ * given timestamp.
+ *
+ * @memberof oak
+ * @method findDescendantsOlderThan
+ * @param {string} path of the parent node to search.
+ * @param {number} timestamp to compare with.
+ */
+ api.findDescendantsOlderThan = function(path, timestamp) {
+ var count = 0;
+ var depth = pathDepth(path);
+ var prefix = path + "/";
+ depth++;
+ var query = { _id: pathFilter(depth, prefix), _modified: {$lt: timestamp}};
+ db.nodes.find(query).forEach(function(doc) {
+ print(doc._id);
+ count++;
+ });
+ print("nCandidates : " + count);
+ }
+
+ /**
+ * Removes all the descendants with a _modified timestamp older than the
+ * given timestamp.
+ * Use removeDescendantsAndSelf() first to get the list of nodes to remove.
+ *
+ * @memberof oak
+ * @method removeDescendantsOlderThan
+ * @param {string} path of the parent node to search.
+ * @param {number} timestamp to compare with.
+ */
+ api.removeDescendantsOlderThan = function(path, timestamp) {
+ var count = 0;
+ var depth = pathDepth(path);
+ var prefix = path + "/";
+ depth++;
+ var query = { _id: pathFilter(depth, prefix), _modified: {$lt: timestamp}};
+ db.nodes.find(query).forEach(function(doc) {
+ print("Removing " + doc._id + " and its children");
+ var result = api.removeDescendantsAndSelf(api.pathFromId(doc._id));
+ count += result.nRemoved;
+ print(" removed : " + result.nRemoved);
+ });
+ print("nRemoved : " + count);
+ }
+
/**
* List all checkpoints.
*
@@ -1195,7 +1242,7 @@ var oak = (function(global){
var i = Math.floor( Math.log(size) / Math.log(1024) );
return ( size / Math.pow(1024, i) ).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
};
-
+
// http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
var escapeForRegExp = function(s) {
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');