<commit_before>/*
 * Helper class for cleaning nedb state
 */
"use strict";
var q = require("q");
var fs = require("fs");

/**
 * Reset the database, wiping all data.
 * @param {String} databaseUri : The database URI to wipe all data from.
 * @return {Promise} Which is resolved when the database has been cleared.
 */
module.exports._reset = function(databaseUri) {
    if (databaseUri.indexOf("nedb://") !== 0) {
        return q.reject("Must be nedb:// URI");
    }
    var baseDbName = databaseUri.substring("nedb://".length);

    var roomDefer = q.defer();
    fs.unlink(baseDbName + "/rooms.db", function(e) {
        if (e) { console.error("rooms.db => %s", e); }
        roomDefer.resolve();
    });

    var configDefer = q.defer();
    fs.unlink(baseDbName + "/config.db", function(e) {
        if (e) { console.error("config.db => %s", e); }
        configDefer.resolve();
    });

    var usersDefer = q.defer();
    fs.unlink(baseDbName + "/users.db", function(e) {
        if (e) { console.error("users.db => %s", e); }
        usersDefer.resolve();
    });

    var ircClientDefer = q.defer();
    fs.unlink(baseDbName + "/irc_clients.db", function(e) {
        if (e) { console.error("irc_clients.db => %s", e); }
        ircClientDefer.resolve();
    });
    return q.all(roomDefer, configDefer, usersDefer, ircClientDefer);
};<commit_msg>Clear databases rather than wiping them to avoid nedb caching breaking tests.<commit_after>/*
 * Helper class for cleaning nedb state
 */
"use strict";
var q = require("q");
var Datastore = require("nedb");

/**
 * Reset the database, wiping all data.
 * @param {String} databaseUri : The database URI to wipe all data from.
 * @return {Promise} Which is resolved when the database has been cleared.
 */
module.exports._reset = function(databaseUri) {
    if (databaseUri.indexOf("nedb://") !== 0) {
        return q.reject("Must be nedb:// URI");
    }
    var baseDbName = databaseUri.substring("nedb://".length);

    function delDatabase(name) {
        var d = q.defer();
        var db = new Datastore({
            filename: baseDbName + name,
            autoload: true,
            onload: function() {
                console.log("Loaded %s", name);
                db.remove({}, {multi: true}, function(err, docs) {
                    if (err) {
                        console.error("db-helper %s Failed to delete: %s", name, err);
                        console.error(err.stack);
                        d.reject(err);
                        return;
                    }
                    d.resolve(docs);
                });
            }
        });
        return d.promise;
    }

    return q.allSettled([
        delDatabase("/config.db"),
        delDatabase("/irc_clients.db"),
        delDatabase("/rooms.db"),
        delDatabase("/users.db")
    ]);
};
{'fraction_non_alphanumeric': 0.15639309616061994, 'fraction_numerical': 0.0007044734061289186, 'mean_word_length': 2.187429854096521, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2722014', 'n_tokens_mistral': 881, 'n_tokens_neox': 844, 'n_words': 222}