Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- queue: function(args, callback){
- var db = this.db;
- var length = args.length;
- var slices = [];
- if(length > 100){
- console.log('mailer.model', 'Splitting Up Large Queue Insert');
- var totalLoops = Math.ceil(length / 100);
- var lastSlice = length - ( totalLoops * 100);
- console.log(length, totalLoops, lastSlice);
- var range = _.range(0, totalLoops);
- range.forEach(function(num, index){
- var start = num === 0 ? num : ((num) * 100) + 1;
- var end = num === 0 ? 100 : start + 99;
- if(end < lastSlice) end = start + lastSlice + 1;
- slices.push(args.slice(start, end));
- console.log(start, 'to', end);
- });
- } else {
- slices = [args];
- }
- slices.forEach(function(slice, index){
- console.log('Slice', 'index');
- var keys = db.mysql.getBulkInsertKeys(slice);
- var data = db.mysql.getBulkInsertData(slice);
- var query = "INSERT INTO mailer_logs ( ?? ) VALUES ?";
- db.mysql.query(query,[keys, data], function(err, result) {
- //console.log(err, result);
- callback(err, result);
- if(err) console.log('mailer.model', 'Queue Insertion Problem', err, response);
- });
- });
- },
Advertisement
Add Comment
Please, Sign In to add comment