mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
feat: async3 upgrade (#7639)
* feat: async3 upgrade WIP * fix: async.doWhilst * fix: async early exit * fix: psql doUntil * fix: psql again
This commit is contained in:
committed by
GitHub
parent
6cebc7f069
commit
4d9bc30d1f
@@ -31,7 +31,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ace-builds": "^1.2.9",
|
"ace-builds": "^1.2.9",
|
||||||
"archiver": "^3.0.0",
|
"archiver": "^3.0.0",
|
||||||
"async": "2.6.2",
|
"async": "3.0.0",
|
||||||
"autoprefixer": "^9.4.6",
|
"autoprefixer": "^9.4.6",
|
||||||
"bcryptjs": "2.4.3",
|
"bcryptjs": "2.4.3",
|
||||||
"benchpressjs": "^1.2.5",
|
"benchpressjs": "^1.2.5",
|
||||||
|
|||||||
@@ -187,9 +187,9 @@ Analytics.getDailyStatsForSet = function (set, day, numDays, callback) {
|
|||||||
day.setDate(day.getDate() + 1); // set the date to tomorrow, because getHourlyStatsForSet steps *backwards* 24 hours to sum up the values
|
day.setDate(day.getDate() + 1); // set the date to tomorrow, because getHourlyStatsForSet steps *backwards* 24 hours to sum up the values
|
||||||
day.setHours(0, 0, 0, 0);
|
day.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
async.whilst(function () {
|
async.whilst(function (next) {
|
||||||
numDays -= 1;
|
numDays -= 1;
|
||||||
return numDays + 1;
|
next(null, numDays + 1);
|
||||||
}, function (next) {
|
}, function (next) {
|
||||||
Analytics.getHourlyStatsForSet(set, day.getTime() - (1000 * 60 * 60 * 24 * numDays), 24, function (err, day) {
|
Analytics.getHourlyStatsForSet(set, day.getTime() - (1000 * 60 * 60 * 24 * numDays), 24, function (err, day) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ exports.processSortedSet = function (setKey, process, options, callback) {
|
|||||||
var done = false;
|
var done = false;
|
||||||
|
|
||||||
async.whilst(
|
async.whilst(
|
||||||
function () {
|
function (next) {
|
||||||
return !done;
|
next(null, !done);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -99,8 +99,8 @@ exports.processArray = function (array, process, options, callback) {
|
|||||||
var done = false;
|
var done = false;
|
||||||
|
|
||||||
async.whilst(
|
async.whilst(
|
||||||
function () {
|
function (next) {
|
||||||
return !done;
|
next(null, !done);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
var currentBatch = array.slice(start, start + batch);
|
var currentBatch = array.slice(start, start + batch);
|
||||||
|
|||||||
@@ -156,8 +156,8 @@ helpers.redirect = function (res, url) {
|
|||||||
helpers.buildCategoryBreadcrumbs = function (cid, callback) {
|
helpers.buildCategoryBreadcrumbs = function (cid, callback) {
|
||||||
var breadcrumbs = [];
|
var breadcrumbs = [];
|
||||||
|
|
||||||
async.whilst(function () {
|
async.whilst(function (next) {
|
||||||
return parseInt(cid, 10);
|
next(null, parseInt(cid, 10));
|
||||||
}, function (next) {
|
}, function (next) {
|
||||||
categories.getCategoryFields(cid, ['name', 'slug', 'parentCid', 'disabled', 'isSection'], function (err, data) {
|
categories.getCategoryFields(cid, ['name', 'slug', 'parentCid', 'disabled', 'isSection'], function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -502,8 +502,8 @@ module.exports = function (db, module) {
|
|||||||
.batchSize(options.batch);
|
.batchSize(options.batch);
|
||||||
|
|
||||||
async.whilst(
|
async.whilst(
|
||||||
function () {
|
function (next) {
|
||||||
return !done;
|
next(null, !done);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
|||||||
@@ -707,14 +707,19 @@ SELECT z."value", z."score"
|
|||||||
WHERE o."_key" = $1::TEXT
|
WHERE o."_key" = $1::TEXT
|
||||||
ORDER BY z."score" ASC, z."value" ASC`, [setKey]));
|
ORDER BY z."score" ASC, z."value" ASC`, [setKey]));
|
||||||
|
|
||||||
async.doUntil(function (next) {
|
var isDone = false;
|
||||||
|
|
||||||
|
async.whilst(function (next) {
|
||||||
|
next(null, !isDone);
|
||||||
|
}, function (next) {
|
||||||
query.read(batchSize, function (err, rows) {
|
query.read(batchSize, function (err, rows) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rows.length) {
|
if (!rows.length) {
|
||||||
return next(null, true);
|
isDone = true;
|
||||||
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
rows = rows.map(function (row) {
|
rows = rows.map(function (row) {
|
||||||
@@ -735,8 +740,6 @@ SELECT z."value", z."score"
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, function (stop) {
|
|
||||||
return stop;
|
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
done();
|
done();
|
||||||
callback(err);
|
callback(err);
|
||||||
|
|||||||
@@ -362,8 +362,8 @@ Messaging.hasPrivateChat = function (uid, withUid, callback) {
|
|||||||
|
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var roomId = 0;
|
var roomId = 0;
|
||||||
async.whilst(function () {
|
async.whilst(function (next) {
|
||||||
return index < roomIds.length && !roomId;
|
next(null, index < roomIds.length && !roomId);
|
||||||
}, function (next) {
|
}, function (next) {
|
||||||
Messaging.getUserCountInRoom(roomIds[index], function (err, count) {
|
Messaging.getUserCountInRoom(roomIds[index], function (err, count) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -243,8 +243,8 @@ module.exports = function (Topics) {
|
|||||||
},
|
},
|
||||||
], next);
|
], next);
|
||||||
},
|
},
|
||||||
function () {
|
function (next) {
|
||||||
return isDeleted && !done;
|
next(null, isDeleted && !done);
|
||||||
},
|
},
|
||||||
function (err) {
|
function (err) {
|
||||||
callback(err, parseInt(latestPid, 10));
|
callback(err, parseInt(latestPid, 10));
|
||||||
|
|||||||
@@ -151,8 +151,8 @@ module.exports = function (Topics) {
|
|||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
], next);
|
], next);
|
||||||
}, function () {
|
}, function (next) {
|
||||||
return isBlocked && prevPost && prevPost.pid && !checkedAllReplies;
|
next(null, isBlocked && prevPost && prevPost.pid && !checkedAllReplies);
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
callback(err, prevPost);
|
callback(err, prevPost);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -298,8 +298,8 @@ module.exports = function (Topics) {
|
|||||||
if (!params.blockedUids.length) {
|
if (!params.blockedUids.length) {
|
||||||
return setImmediate(callback, null, hasUnblockedUnread);
|
return setImmediate(callback, null, hasUnblockedUnread);
|
||||||
}
|
}
|
||||||
async.whilst(function () {
|
async.whilst(function (next) {
|
||||||
return !done;
|
next(null, !done);
|
||||||
}, function (_next) {
|
}, function (_next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ module.exports = {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
var currentChatRoomId = 1;
|
var currentChatRoomId = 1;
|
||||||
async.whilst(function () {
|
async.whilst(function (next) {
|
||||||
return currentChatRoomId <= nextChatRoomId;
|
next(null, currentChatRoomId <= nextChatRoomId);
|
||||||
}, function (next) {
|
}, function (next) {
|
||||||
db.getSortedSetRange('chat:room:' + currentChatRoomId + ':uids', 0, 0, function (err, uids) {
|
db.getSortedSetRange('chat:room:' + currentChatRoomId + ':uids', 0, 0, function (err, uids) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ module.exports = {
|
|||||||
var roomId = globalData.nextChatRoomId || 1;
|
var roomId = globalData.nextChatRoomId || 1;
|
||||||
var currentMid = 1;
|
var currentMid = 1;
|
||||||
|
|
||||||
async.whilst(function () {
|
async.whilst(function (next) {
|
||||||
return currentMid <= globalData.nextMid;
|
next(null, currentMid <= globalData.nextMid);
|
||||||
}, function (next) {
|
}, function (next) {
|
||||||
db.getObject('message:' + currentMid, function (err, message) {
|
db.getObject('message:' + currentMid, function (err, message) {
|
||||||
var msgTime;
|
var msgTime;
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ module.exports = {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
progress.total = nextUid;
|
progress.total = nextUid;
|
||||||
async.whilst(function () {
|
async.whilst(function (next) {
|
||||||
return currentUid < nextUid;
|
next(null, currentUid < nextUid);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
progress.incr();
|
progress.incr();
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ module.exports = {
|
|||||||
|
|
||||||
var done = false;
|
var done = false;
|
||||||
async.whilst(
|
async.whilst(
|
||||||
function () {
|
function (next) {
|
||||||
return !done;
|
next(null, !done);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ admin.get = function (callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(false, {
|
callback(null, {
|
||||||
templates: buildTemplatesFromAreas(widgetData.areas),
|
templates: buildTemplatesFromAreas(widgetData.areas),
|
||||||
areas: widgetData.areas,
|
areas: widgetData.areas,
|
||||||
availableWidgets: widgetData.availableWidgets,
|
availableWidgets: widgetData.availableWidgets,
|
||||||
|
|||||||
Reference in New Issue
Block a user