mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-14 10:37:45 +01:00
refactor: get rid of map, move parallel calls into promise.all
This commit is contained in:
@@ -163,25 +163,25 @@ Digest.send = async function (data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Digest.getDeliveryTimes = async (start, stop) => {
|
Digest.getDeliveryTimes = async (start, stop) => {
|
||||||
const count = await db.sortedSetCard('users:joindate');
|
const [count, uids] = await Promise.all([
|
||||||
const uids = await user.getUidsFromSet('users:joindate', start, stop);
|
db.sortedSetCard('users:joindate'),
|
||||||
|
user.getUidsFromSet('users:joindate', start, stop),
|
||||||
|
]);
|
||||||
if (!uids.length) {
|
if (!uids.length) {
|
||||||
return [];
|
return { users: [], count };
|
||||||
}
|
}
|
||||||
|
|
||||||
const [scores, settings] = await Promise.all([
|
const [scores, settings, userData] = await Promise.all([
|
||||||
// Grab the last time a digest was successfully delivered to these uids
|
// Grab the last time a digest was successfully delivered to these uids
|
||||||
db.sortedSetScores('digest:delivery', uids),
|
db.sortedSetScores('digest:delivery', uids),
|
||||||
// Get users' digest settings
|
// Get users' digest settings
|
||||||
Digest.getUsersInterval(uids),
|
Digest.getUsersInterval(uids),
|
||||||
|
user.getUsersFields(uids, ['username', 'picture']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Populate user data
|
userData.forEach((user, idx) => {
|
||||||
let userData = await user.getUsersFields(uids, ['username', 'picture']);
|
|
||||||
userData = userData.map((user, idx) => {
|
|
||||||
user.lastDelivery = scores[idx] ? new Date(scores[idx]).toISOString() : '[[admin/manage/digest:null]]';
|
user.lastDelivery = scores[idx] ? new Date(scores[idx]).toISOString() : '[[admin/manage/digest:null]]';
|
||||||
user.setting = settings[idx];
|
user.setting = settings[idx];
|
||||||
return user;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user