<commit_before>// Dacleaner machine
'use strict';

var db = require('riak-js').getClient();

var prefix = "gitification_";

var delete_key = function (bucket, key) {
	db.remove(bucket, key);
	console.log("remove: " + bucket + "/" + key);
};

var delete_keys = function (bucketname, keys) {
	keys.forEach(
		function (key) {
			delete_key(bucketname, key);
		});
};


function isBucketOur(element/*, index, array*/) {
	return (element.substring(0, prefix.length) === prefix);
}


function delete_buckets(err, buckets) {
	var ourBuckets = buckets.filter(isBucketOur);
	console.log("our buckets: " + ourBuckets);
	ourBuckets.forEach(
		function (bucket) {
			db.keys(bucket, { keys: 'stream' }).on('keys', function (streamer) {
				delete_keys(bucket, streamer);
			}).start();
		});
}

db.buckets(delete_buckets);



<commit_msg>Robust implementation with async, log error<commit_after>// Dacleaner machine
'use strict';

var db = require('riak-js').getClient();
var async = require('async');

var prefix = "gitification_";

var delete_key = function (bucket, key, callback) {
	db.remove(bucket, key, function (err) {
		console.log("removed: " + bucket + "/" + key + ", with error " + err);
		callback();
	});
};

var delete_keys = function (bucketname, keys, callback) {
	async.each(keys, function (key, cb) {
		delete_key(bucketname, key, cb);
	}, function (err) {
		callback();
	}
	);
};


function isBucketOur(element/*, index, array*/) {
	return (element.substring(0, prefix.length) === prefix);
}


function delete_buckets(err, buckets) {
	var ourBuckets = buckets.filter(isBucketOur);
	console.log("our buckets: " + ourBuckets);

	async.eachSeries(ourBuckets, function (bucket, cb) {
		var stream = db.keys(bucket, {keys: 'stream'});
        	var keys = []
            	stream.on('keys', function(someKeys) {
              		keys = keys.concat(someKeys);
           	}).on('end', function(data) {
              		delete_keys(bucket, keys, cb);
            	}).start();
	}, function (err) {
		if (err) { console.log("error" + err); }
		console.log("finished");
	}
	);
}

db.buckets(delete_buckets);




{'fraction_non_alphanumeric': 0.1737891737891738, 'fraction_numerical': 0.000949667616334283, 'mean_word_length': 3.84367816091954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7613534', 'n_tokens_mistral': 757, 'n_tokens_neox': 709, 'n_words': 159}