From 93863bb3c6704d4eac15d69b4a2a5951247f8742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 26 Nov 2020 00:01:59 -0500 Subject: [PATCH] fix: #8949, faster upgrade script --- src/upgrades/1.15.0/verified_users_group.js | 26 ++++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/upgrades/1.15.0/verified_users_group.js b/src/upgrades/1.15.0/verified_users_group.js index 7e5bcd4c64..7f6736b1ef 100644 --- a/src/upgrades/1.15.0/verified_users_group.js +++ b/src/upgrades/1.15.0/verified_users_group.js @@ -7,7 +7,7 @@ const user = require('../../user'); const groups = require('../../groups'); const meta = require('../../meta'); const privileges = require('../../privileges'); - +const now = Date.now(); module.exports = { name: 'Create verified/unverified user groups', timestamp: Date.UTC(2020, 9, 13), @@ -46,14 +46,17 @@ module.exports = { const verified = userData.filter(u => parseInt(u['email:confirmed'], 10) === 1); const unverified = userData.filter(u => parseInt(u['email:confirmed'], 10) !== 1); - for (const user of verified) { - // eslint-disable-next-line no-await-in-loop - await groups.join('verified-users', user.uid); - } - for (const user of unverified) { - // eslint-disable-next-line no-await-in-loop - await groups.join('unverified-users', user.uid); - } + await db.sortedSetAdd( + 'group:verified-users:members', + verified.map(() => now), + verified.map(u => u.uid) + ); + + await db.sortedSetAdd( + 'group:unverified-users:members', + verified.map(() => now), + unverified.map(u => u.uid) + ); }, { batch: 500, progress: this.progress, @@ -61,6 +64,11 @@ module.exports = { await db.delete('users:notvalidated'); await updatePrivilges(); + + const verifiedCount = await db.sortedSetCard('group:verified-users:members'); + const unverifiedCount = await db.sortedSetCard('group:unverified-users:members'); + await db.setObjectField('group:verified-users', 'memberCount', verifiedCount); + await db.setObjectField('group:unverified-users', 'memberCount', unverifiedCount); }, };