refactor: remove async.series, use batch.processSortedSet

This commit is contained in:
Barış Soner Uşaklı
2026-03-12 10:50:01 -04:00
parent 02f8ea2c94
commit 894248e60d
2 changed files with 11 additions and 10 deletions

View File

@@ -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-loop
await posts.unvote(pid, uid);
});
}
}
async function deleteChats(uid) {

View File

@@ -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])}`),
]);