using async in batch

removed unused code in debug
v1.18.x
Baris Usakli 8 years ago
parent 922790cc40
commit d469f53eba

@ -49,18 +49,20 @@ exports.processSortedSet = function (setKey, process, options, callback) {
return !done;
},
function (next) {
db.getSortedSetRange(setKey, start, stop, function (err, ids) {
if (err) {
return next(err);
}
if (!ids.length || options.doneIf(start, stop, ids)) {
done = true;
return next();
}
process(ids, function (err) {
if (err) {
return next(err);
async.waterfall([
function (next) {
db.getSortedSetRange(setKey, start, stop, next);
},
function (ids, _next) {
if (!ids.length || options.doneIf(start, stop, ids)) {
done = true;
return next();
}
process(ids, function (err) {
_next(err);
});
},
function (next) {
start += utils.isNumber(options.alwaysStartAt) ? options.alwaysStartAt : options.batch + 1;
stop = start + options.batch;
@ -69,8 +71,8 @@ exports.processSortedSet = function (setKey, process, options, callback) {
} else {
next();
}
});
});
},
], next);
},
callback
);
@ -106,17 +108,21 @@ exports.processArray = function (array, process, options, callback) {
done = true;
return next();
}
process(currentBatch, function (err) {
if (err) {
return next(err);
}
start += batch;
if (options.interval) {
setTimeout(next, options.interval);
} else {
next();
}
});
async.waterfall([
function (next) {
process(currentBatch, function (err) {
next(err);
});
},
function (next) {
start += batch;
if (options.interval) {
setTimeout(next, options.interval);
} else {
next();
}
},
], next);
},
function (err) {
callback(err);

@ -480,32 +480,33 @@ module.exports = function (db, module) {
return !done;
},
function (next) {
cursor.next(function (err, item) {
if (err) {
return next(err);
}
if (item === null) {
done = true;
} else {
ids.push(item.value);
}
if (ids.length < options.batch && (!done || ids.length === 0)) {
return next(null);
}
process(ids, function (err) {
if (err) {
return next(err);
async.waterfall([
function (next) {
cursor.next(next);
},
function (item, _next) {
if (item === null) {
done = true;
} else {
ids.push(item.value);
}
if (ids.length < options.batch && (!done || ids.length === 0)) {
return next(null);
}
process(ids, function (err) {
_next(err);
});
},
function (next) {
ids = [];
if (options.interval) {
setTimeout(next, options.interval);
} else {
next();
}
});
});
},
], next);
},
callback
);

@ -2,77 +2,10 @@
var express = require('express');
var nconf = require('nconf');
var winston = require('winston');
var user = require('../user');
var categories = require('../categories');
var topics = require('../topics');
var posts = require('../posts');
module.exports = function (app) {
var router = express.Router();
router.get('/uid/:uid', function (req, res) {
if (!req.params.uid) {
return res.redirect('/404');
}
user.getUserData(req.params.uid, function (err, data) {
if (err) {
winston.error(err);
}
if (data) {
res.send(data);
} else {
res.status(404).json({
error: "User doesn't exist!",
});
}
});
});
router.get('/cid/:cid', function (req, res) {
categories.getCategoryData(req.params.cid, function (err, data) {
if (err) {
winston.error(err);
}
if (data) {
res.send(data);
} else {
res.status(404).send("Category doesn't exist!");
}
});
});
router.get('/tid/:tid', function (req, res) {
topics.getTopicData(req.params.tid, function (err, data) {
if (err) {
winston.error(err);
}
if (data) {
res.send(data);
} else {
res.status(404).send("Topic doesn't exist!");
}
});
});
router.get('/pid/:pid', function (req, res) {
posts.getPostData(req.params.pid, function (err, data) {
if (err) {
winston.error(err);
}
if (data) {
res.send(data);
} else {
res.status(404).send("Post doesn't exist!");
}
});
});
router.get('/test', function (req, res) {
res.redirect(404);
});

Loading…
Cancel
Save