mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-27 17:11:14 +01:00
fix: update follower/following counts after removing uid from zsets
use batch instead of async.each
This commit is contained in:
@@ -209,18 +209,22 @@ module.exports = function (User) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
async function updateCount(uids, name, fieldName) {
|
async function updateCount(uids, name, fieldName) {
|
||||||
await async.each(uids, async (uid) => {
|
await batch.processArray(uids, async (uids) => {
|
||||||
let count = await db.sortedSetCard(name + uid);
|
const counts = await db.sortedSetsCard(uids.map(uid => name + uid));
|
||||||
count = parseInt(count, 10) || 0;
|
const bulkSet = counts.map(
|
||||||
await db.setObjectField(`user:${uid}`, fieldName, count);
|
(count, index) => ([`user:${uids[index]}`, { [fieldName]: count || 0 }])
|
||||||
|
);
|
||||||
|
await db.setObjectBulk(bulkSet);
|
||||||
|
}, {
|
||||||
|
batch: 500,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const followingSets = followers.map(uid => `following:${uid}`);
|
const followingSets = followers.map(uid => `following:${uid}`);
|
||||||
const followerSets = following.map(uid => `followers:${uid}`);
|
const followerSets = following.map(uid => `followers:${uid}`);
|
||||||
|
|
||||||
|
await db.sortedSetsRemove(followerSets.concat(followingSets), uid);
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
db.sortedSetsRemove(followerSets.concat(followingSets), uid),
|
|
||||||
updateCount(following, 'followers:', 'followerCount'),
|
updateCount(following, 'followers:', 'followerCount'),
|
||||||
updateCount(followers, 'following:', 'followingCount'),
|
updateCount(followers, 'following:', 'followingCount'),
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user