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

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

@ -2,77 +2,10 @@
var express = require('express'); var express = require('express');
var nconf = require('nconf'); 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) { module.exports = function (app) {
var router = express.Router(); 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) { router.get('/test', function (req, res) {
res.redirect(404); res.redirect(404);
}); });

Loading…
Cancel
Save