From c5f72e6018076b5e8fa1c91faa7d73a749385d4f Mon Sep 17 00:00:00 2001 From: Talal Date: Wed, 4 Sep 2024 10:25:22 +0300 Subject: [PATCH 1/2] Reworked the updateCount function and moved it to avoid the nesting issue --- src/user/delete.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/user/delete.js b/src/user/delete.js index 8f99117c59..13f36548e4 100644 --- a/src/user/delete.js +++ b/src/user/delete.js @@ -15,6 +15,19 @@ const messaging = require('../messaging'); const plugins = require('../plugins'); const batch = require('../batch'); +async function updateCount(uids, name, fieldName) { + await batch.processArray(uids, async (uids) => { + const counts = await db.sortedSetsCard(uids.map(uid => name + uid)); + const bulkSet = counts.map( + (count, index) => ([`user:${uids[index]}`, { [fieldName]: count || 0 }]) + ); + await db.setObjectBulk(bulkSet); + }, { + batch: 500, + }); +} + + module.exports = function (User) { const deletesInProgress = {}; @@ -208,17 +221,6 @@ module.exports = function (User) { db.getSortedSetRange(`following:${uid}`, 0, -1), ]); - async function updateCount(uids, name, fieldName) { - await batch.processArray(uids, async (uids) => { - const counts = await db.sortedSetsCard(uids.map(uid => name + uid)); - const bulkSet = counts.map( - (count, index) => ([`user:${uids[index]}`, { [fieldName]: count || 0 }]) - ); - await db.setObjectBulk(bulkSet); - }, { - batch: 500, - }); - } const followingSets = followers.map(uid => `following:${uid}`); const followerSets = following.map(uid => `followers:${uid}`); From 29cf1f31d572295904bb787e549094b9e208cff2 Mon Sep 17 00:00:00 2001 From: Talal Date: Wed, 4 Sep 2024 19:44:25 +0300 Subject: [PATCH 2/2] added logs inthe updateCount function for testing --- src/user/delete.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/user/delete.js b/src/user/delete.js index 13f36548e4..51ce498fde 100644 --- a/src/user/delete.js +++ b/src/user/delete.js @@ -16,6 +16,7 @@ const plugins = require('../plugins'); const batch = require('../batch'); async function updateCount(uids, name, fieldName) { + console.log('Talal: Starting updateCount function'); await batch.processArray(uids, async (uids) => { const counts = await db.sortedSetsCard(uids.map(uid => name + uid)); const bulkSet = counts.map( @@ -25,6 +26,7 @@ async function updateCount(uids, name, fieldName) { }, { batch: 500, }); + console.log('Talal: Finished updateCount function'); }