mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
refactor: remove more async.eachSeries/mapSeries
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const async = require('async');
|
||||
|
||||
const db = require('../database');
|
||||
const meta = require('../meta');
|
||||
const utils = require('../utils');
|
||||
@@ -37,9 +35,10 @@ module.exports = function (Categories) {
|
||||
fields.splice(0, 0, fields.splice(parentCidIndex, 1)[0]);
|
||||
}
|
||||
|
||||
await async.eachSeries(fields, async (key) => {
|
||||
for (const key of fields) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await updateCategoryField(cid, key, category[key]);
|
||||
});
|
||||
}
|
||||
plugins.hooks.fire('action:category.update', { cid: cid, modified: category });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const async = require('async');
|
||||
const winston = require('winston');
|
||||
|
||||
const db = require('../database');
|
||||
@@ -75,8 +74,9 @@ module.exports = function (Groups) {
|
||||
return;
|
||||
}
|
||||
|
||||
await async.eachSeries(groupsToCreate, async (groupName) => {
|
||||
for (const groupName of groupsToCreate) {
|
||||
try {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await Groups.create({
|
||||
name: groupName,
|
||||
hidden: 1,
|
||||
@@ -87,7 +87,7 @@ module.exports = function (Groups) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function setGroupTitleIfNotSet(groupNames, uid) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const async = require('async');
|
||||
const db = require('../database');
|
||||
|
||||
const user = require('../user');
|
||||
@@ -60,10 +59,11 @@ module.exports = function (Topics) {
|
||||
|
||||
Topics.purgePostsAndTopic = async function (tid, uid) {
|
||||
const mainPid = await Topics.getTopicField(tid, 'mainPid');
|
||||
await batch.processSortedSet(`tid:${tid}:posts`, (pids, next) => {
|
||||
async.eachSeries(pids, (pid, next) => {
|
||||
posts.purge(pid, uid, next);
|
||||
}, next);
|
||||
await batch.processSortedSet(`tid:${tid}:posts`, async (pids) => {
|
||||
for (const pid of pids) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await posts.purge(pid, uid);
|
||||
}
|
||||
}, { alwaysStartAt: 0 });
|
||||
await posts.purge(mainPid, uid);
|
||||
await Topics.purge(tid, uid);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const async = require('async');
|
||||
|
||||
const db = require('../database');
|
||||
const posts = require('../posts');
|
||||
const categories = require('../categories');
|
||||
@@ -55,13 +53,14 @@ module.exports = function (Topics) {
|
||||
const tid = await Topics.create(result.params);
|
||||
await Topics.updateTopicBookmarks(fromTid, pids);
|
||||
|
||||
await async.eachSeries(pids, async (pid) => {
|
||||
for (const pid of pids) {
|
||||
/* eslint-disable no-await-in-loop */
|
||||
const canEdit = await privileges.posts.canEdit(pid, uid);
|
||||
if (!canEdit.flag) {
|
||||
throw new Error(canEdit.message);
|
||||
}
|
||||
await Topics.movePostToTopic(uid, pid, tid, scheduled);
|
||||
});
|
||||
}
|
||||
|
||||
await Topics.updateLastPostTime(tid, scheduled ? (postData.timestamp + 1) : Date.now());
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const async = require('async');
|
||||
const plugins = require('../plugins');
|
||||
const posts = require('../posts');
|
||||
|
||||
@@ -24,11 +23,12 @@ module.exports = function (Topics) {
|
||||
const otherTids = tids.sort((a, b) => a - b)
|
||||
.filter(tid => tid && parseInt(tid, 10) !== parseInt(mergeIntoTid, 10));
|
||||
|
||||
await async.eachSeries(otherTids, async (tid) => {
|
||||
for (const tid of otherTids) {
|
||||
/* eslint-disable no-await-in-loop */
|
||||
const pids = await Topics.getPids(tid);
|
||||
await async.eachSeries(pids, (pid, next) => {
|
||||
Topics.movePostToTopic(uid, pid, mergeIntoTid, next);
|
||||
});
|
||||
for (const pid of pids) {
|
||||
await Topics.movePostToTopic(uid, pid, mergeIntoTid);
|
||||
}
|
||||
|
||||
await Topics.setTopicField(tid, 'mainPid', 0);
|
||||
await Topics.delete(tid, uid);
|
||||
@@ -37,7 +37,7 @@ module.exports = function (Topics) {
|
||||
mergerUid: uid,
|
||||
mergedTimestamp: Date.now(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
posts.updateQueuedPostsTopic(mergeIntoTid, otherTids),
|
||||
|
||||
@@ -116,9 +116,10 @@ module.exports = function (Topics) {
|
||||
};
|
||||
|
||||
Topics.renameTags = async function (data) {
|
||||
await async.eachSeries(data, async (tagData) => {
|
||||
for (const tagData of data) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await renameTag(tagData.value, tagData.newName);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
async function renameTag(tag, newTagName) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const async = require('async');
|
||||
const _ = require('lodash');
|
||||
|
||||
const db = require('../database');
|
||||
@@ -111,12 +110,12 @@ module.exports = function (Topics) {
|
||||
return teasers;
|
||||
}
|
||||
|
||||
return await async.mapSeries(teasers, async (postData) => {
|
||||
return await Promise.all(teasers.map(async (postData) => {
|
||||
if (blockedUids.includes(parseInt(postData.uid, 10))) {
|
||||
return await getPreviousNonBlockedPost(postData, blockedUids);
|
||||
}
|
||||
return postData;
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
async function getPreviousNonBlockedPost(postData, blockedUids) {
|
||||
|
||||
Reference in New Issue
Block a user