<commit_before>/*
 @author <NAME>
 @component DbEvents
 */

screens.db.events = function DbEvents(me, packages) {
    return "server";
};

screens.db.events.participants = function DbEventsParticipants(me, packages) {
    const { storage } = packages;
    me.init = () => storage.db.extension(me);
    me.cache = {};
    me.options = { capped: true, size: 242880, max: 250 };
    return "server";
};

screens.db.events.logs = function DbEventsLogs(me, packages) {
    const { storage } = packages;
    me.init = () => storage.db.extension(me);
    me.options = { capped: true, size: 242880, max: 500 };
    return "server";
};

screens.db.events.servers = function DbEventsServers(me, packages) {
    const { core, storage } = packages;
    me.init = async () => {
        storage.db.extension(me);
        core.broadcast.register(me, {
            startup: "db.events.servers.register",
            shutdown: "db.events.servers.unregister"
        });
    };
    me.register = async function () {
        let ip = await core.server.ip();
        me.use({ ip }, { date: new Date().toString() });
    };
    me.unregister = async function () {
        let ip = await core.server.ip();
        me.remove({ ip });
    };
    return "server";
};

screens.db.events.msg = function DbEventsMsg(me, packages) {
    const { core, storage } = packages;
    me.lastMsgId = 0;
    me.busy = false;
    me.init = async () => {
        storage.db.extension(me);
        setInterval(me.handleNextMsg, 10000);
    };
    me.options = { capped: true, size: 64000, max: 1000 };
    me.handleNextMsg = async function () {
        let ip = await core.server.ip();
        if (!me.storage.db.supported()) {
            return;
        }
        if (me.busy) {
            return;
        }
        me.busy = true;
        try {
            var list = await me.list();
            if (!list) {
                return;
            }
            if (!list.length) {
                return;
            }
            var index = list.findIndex((item) => item._id === me.lastMsgId);
            if (index == -1) {
                me.lastMsgId = list[list.length - 1]._id;
                return;
            }
            for (index++; index < list.length; index++) {
                var item = list[index];
                if (!item.ip || item.ip === ip) {
                    me.log("running message: " + index + " - " + item.date + " - " + JSON.stringify(item.args));
                    try {
                        await core.message.send.apply(null, item.args);
                    }
                    catch (err) {
                        me.log_error("Cannot handle message" + JSON.stringify(item.args) + " err:" + err);
                    }
                }
                else {
                    me.log("ignoring message: " + index + " - " + item.date + " - " + JSON.stringify(item.args) + " ip: " + item.ip);
                }
                me.lastMsgId = item._id;
            }
        }
        catch (err) {
            me.log_error("Cannot handle messages : " + err);
        }
        finally {
            me.busy = false;
        }
    };
    me.send = function (method) {
        var args = Array.prototype.slice.call(arguments, 0);
        me.push({ date: new Date().toString(), args });
    };
    me.sendTo = function (ip, method) {
        var args = Array.prototype.slice.call(arguments, 1);
        me.push({ date: new Date().toString(), args, ip });
    };
    return "server";
};<commit_msg>remove log<commit_after>/*
 @author <NAME>
 @component DbEvents
 */

screens.db.events = function DbEvents(me, packages) {
    return "server";
};

screens.db.events.participants = function DbEventsParticipants(me, packages) {
    const { storage } = packages;
    me.init = () => storage.db.extension(me);
    me.cache = {};
    me.options = { capped: true, size: 242880, max: 250 };
    return "server";
};

screens.db.events.logs = function DbEventsLogs(me, packages) {
    const { storage } = packages;
    me.init = () => storage.db.extension(me);
    me.options = { capped: true, size: 242880, max: 500 };
    return "server";
};

screens.db.events.servers = function DbEventsServers(me, packages) {
    const { core, storage } = packages;
    me.init = async () => {
        storage.db.extension(me);
        core.broadcast.register(me, {
            startup: "db.events.servers.register",
            shutdown: "db.events.servers.unregister"
        });
    };
    me.register = async function () {
        let ip = await core.server.ip();
        me.use({ ip }, { date: new Date().toString() });
    };
    me.unregister = async function () {
        let ip = await core.server.ip();
        me.remove({ ip });
    };
    return "server";
};

screens.db.events.msg = function DbEventsMsg(me, packages) {
    const { core, storage } = packages;
    me.lastMsgId = 0;
    me.busy = false;
    me.init = async () => {
        storage.db.extension(me);
        setInterval(me.handleNextMsg, 10000);
    };
    me.options = { capped: true, size: 64000, max: 1000 };
    me.handleNextMsg = async function () {
        let ip = await core.server.ip();
        if (!me.storage.db.supported()) {
            return;
        }
        if (me.busy) {
            return;
        }
        me.busy = true;
        try {
            var list = await me.list();
            if (!list) {
                return;
            }
            if (!list.length) {
                return;
            }
            var index = list.findIndex((item) => item._id === me.lastMsgId);
            if (index == -1) {
                me.lastMsgId = list[list.length - 1]._id;
                return;
            }
            for (index++; index < list.length; index++) {
                var item = list[index];
                if (!item.ip || item.ip === ip) {
                    me.log("running message: " + index + " - " + item.date + " - " + JSON.stringify(item.args));
                    try {
                        await core.message.send.apply(null, item.args);
                    }
                    catch (err) {
                        me.log_error("Cannot handle message" + JSON.stringify(item.args) + " err:" + err);
                    }
                }
                me.lastMsgId = item._id;
            }
        }
        catch (err) {
            me.log_error("Cannot handle messages : " + err);
        }
        finally {
            me.busy = false;
        }
    };
    me.send = function (method) {
        var args = Array.prototype.slice.call(arguments, 0);
        me.push({ date: new Date().toString(), args });
    };
    me.sendTo = function (ip, method) {
        var args = Array.prototype.slice.call(arguments, 1);
        me.push({ date: new Date().toString(), args, ip });
    };
    return "server";
};
{'fraction_non_alphanumeric': 0.15090749414519905, 'fraction_numerical': 0.010831381733021077, 'mean_word_length': 1.6150019135093763, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '3814507', 'n_tokens_mistral': 2118, 'n_tokens_neox': 2014, 'n_words': 443}