Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAK-10801: Introduce functions to remove nodes that are older than a timestamp #1451

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion oak-run/src/main/js/oak-mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Use removeDescendantsAndSelf() first to get the list of nodes to remove.
* Use findDescendantsOlderThan() first to get the list of nodes to remove.

Was this indeed meant to refer to removeDescendantsAndSelf, or not findDescendantsOlderThan?

*
* @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.
*
Expand Down Expand Up @@ -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, '\\$&');
Expand Down
Loading