Node.js based forum software built for the modern web
refactor: remove async.series, use batch.processSortedSet
Barış Soner Uşaklı894248e60dea
diff --git a/src/user/delete.js b/src/user/delete.jsindex 12cdbb588d..9deecd001b 100644--- a/src/user/delete.js+++ b/src/user/delete.js@@ -1,6 +1,5 @@'use strict';-const async = require('async');const _ = require('lodash');const path = require('path');const nconf = require('nconf');@@ -60,8 +59,9 @@ module.exports = function (User) {}async function deleteUploads(callerUid, uid) {- const uploads = await db.getSortedSetMembers(`uid:${uid}:uploads`);- await User.deleteUpload(callerUid, uid, uploads);+ await batch.processSortedSet(`uid:${uid}:uploads`, async (uploads) => {+ await User.deleteUpload(callerUid, uid, uploads);+ }, { alwaysStartAt: 0, batch: 500 });}async function deleteQueued(uid) {@@ -71,7 +71,11 @@ module.exports = function (User) {const userQueuedIds = data.filter(d => String(d.uid) === String(uid)).map(d => d.id);deleteIds = deleteIds.concat(userQueuedIds);}, { batch: 500 });- await async.eachSeries(deleteIds, posts.removeFromQueue);++ for (const id of deleteIds) {+ // eslint-disable-next-line no-await-in-loop+ await posts.removeFromQueue(id);+ }}async function removeFromSortedSets(uid) {@@ -195,9 +199,10 @@ module.exports = function (User) {`uid:${uid}:upvote`, `uid:${uid}:downvote`,], 0, -1);const pids = _.uniq(upvoteDownvotePids).filter(Boolean);- await async.eachSeries(pids, async (pid) => {+ for (const pid of pids) {+ // eslint-disable-next-line no-await-in-loopawait posts.unvote(pid, uid);- });+ }}async function deleteChats(uid) {diff --git a/src/user/uploads.js b/src/user/uploads.jsindex b373d48b6b..7d004fdc37 100644--- a/src/user/uploads.js+++ b/src/user/uploads.js@@ -2,7 +2,6 @@const path = require('path');const nconf = require('nconf');-const winston = require('winston');const crypto = require('crypto');const db = require('../database');@@ -61,12 +60,9 @@ module.exports = function (User) {const fullPaths = uploadNames.map(path => _getFullPath(path));await Promise.all(fullPaths.map(async (fullPath, idx) => {- winston.verbose(`[user/deleteUpload] Deleting ${uploadNames[idx]}`);await Promise.all([file.delete(fullPath),file.delete(file.appendToFileName(fullPath, '-resized')),- ]);- await Promise.all([db.sortedSetRemove(`uid:${uid}:uploads`, uploadNames[idx]),db.delete(`upload:${md5(uploadNames[idx])}`),]);