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