Node.js based forum software built for the modern web
refactor: remove more async.eachSeries/mapSeries
Barış Soner Uşaklıd1964095803e
diff --git a/src/categories/update.js b/src/categories/update.jsindex 04650a4c46..259dd58d06 100644--- a/src/categories/update.js+++ b/src/categories/update.js@@ -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-loopawait updateCategoryField(cid, key, category[key]);- });+ }plugins.hooks.fire('action:category.update', { cid: cid, modified: category });}diff --git a/src/groups/join.js b/src/groups/join.jsindex 7b7a68095e..9fb02ec0bb 100644--- a/src/groups/join.js+++ b/src/groups/join.js@@ -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-loopawait Groups.create({name: groupName,hidden: 1,@@ -87,7 +87,7 @@ module.exports = function (Groups) {throw err;}}- });+ }}async function setGroupTitleIfNotSet(groupNames, uid) {diff --git a/src/topics/delete.js b/src/topics/delete.jsindex 3e84a29cc8..34d581e49d 100644--- a/src/topics/delete.js+++ b/src/topics/delete.js@@ -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);diff --git a/src/topics/fork.js b/src/topics/fork.jsindex 5005dd1696..aa16168c87 100644--- a/src/topics/fork.js+++ b/src/topics/fork.js@@ -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());diff --git a/src/topics/merge.js b/src/topics/merge.jsindex 33684491ae..1a06adefbb 100644--- a/src/topics/merge.js+++ b/src/topics/merge.js@@ -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),diff --git a/src/topics/tags.js b/src/topics/tags.jsindex f47dc2aad5..b0be277a9d 100644--- a/src/topics/tags.js+++ b/src/topics/tags.js@@ -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-loopawait renameTag(tagData.value, tagData.newName);- });+ }};async function renameTag(tag, newTagName) {diff --git a/src/topics/teaser.js b/src/topics/teaser.jsindex 11473f4d64..f5815f8deb 100644--- a/src/topics/teaser.js+++ b/src/topics/teaser.js@@ -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) {