<commit_before>(function () {
    var cogClass = function () {};
    cogClass.prototype.exec = function (params, request, response) {
        var oops = this.utils.apiError;
        var sys = this.sys;
        var getRandomKey = this.sys.getRandomKey;
        var classID = params.classid;
        var getClassMemberships = this.utils.getClassMemberships;
        var stmt = sys.db.prepare('INSERT INTO memberships VALUES(NULL,?,?,?,NULL);');
        for (var i=0,ilen=params.addmembers.length;i<ilen;i+=1) {
            var addmemberID = params.addmembers[i];
            var addmemberKey = getRandomKey(8,36);
            stmt.bind(classID,addmemberID,addmemberKey);
            stmt.run();
            stmt.reset();
        }
        stmt.finalize(function(){
            getClassMemberships(params,request,response);
        });
    }
    exports.cogClass = cogClass;
})();
<commit_msg>Rationalize code in addmembers<commit_after>(function () {
    var cogClass = function () {};
    cogClass.prototype.exec = function (params, request, response) {
        var oops = this.utils.apiError;
        var sys = this.sys;
        var getRandomKey = this.sys.getRandomKey;
        var classID = params.classid;
        var getClassMemberships = this.utils.getClassMemberships;

        sys.db.run('BEGIN TRANSACTION',function(err){
            if (err){return oops(response,err,'class/addmembers(1)')};
            addMembers(0,params.addmembers.length);
        });

        function addMembers(pos,limit) {
            if (pos === limit) {
                endTransaction();
            }
            var sql = 'INSERT INTO memberships VALUES(NULL,?,?,?,NULL);';
            var addmemberID = params.addmembers[pos];
            var addmemberKey = getRandomKey(8,36);
            sys.db.run(sql,[classID,addmemberID,addmemberKey],function(err){
                if (err){return oops(response,err,'class/addmembers(2)')};
                addMembers(pos+1,limit);
            });
        };
        
        function endTransaction() {
            sys.db.run('END TRANSACTION',function(err){
                if (err){return oops(response,err,'class/addmembers(3)')};
                getClassMemberships(params,request,response);
            });
        };
    }
    exports.cogClass = cogClass;
})();

{'fraction_non_alphanumeric': 0.13365259033521984, 'fraction_numerical': 0.0056595559425337396, 'mean_word_length': 2.282857142857143, 'pattern_counts': {'":': 0, '<': 4, '<?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': '917338', 'n_tokens_mistral': 686, 'n_tokens_neox': 660, 'n_words': 112}