diff --git a/src/groups/index.js b/src/groups/index.js index bf2a93cf97..c6db18e99f 100644 --- a/src/groups/index.js +++ b/src/groups/index.js @@ -154,17 +154,12 @@ Groups.getOwnersAndMembers = async function (groupName, uid, start, stop) { } }); - let done = false; let returnUsers = owners; - let memberStart = start - ownerUids.length + 1; - let memberStop = memberStart + countToReturn - 1; - memberStart = Math.max(0, memberStart); - memberStop = Math.max(0, memberStop); + const memberStart = Math.max(0, start - ownerUids.length + 1); + const memberStop = memberStart + countToReturn; + async function addMembers(start, stop) { let batch = await user.getUsersFromSet('group:' + groupName + ':members', uid, start, stop); - if (!batch.length) { - done = true; - } batch = batch.filter(user => user && user.uid && !ownerUids.includes(user.uid.toString())); returnUsers = returnUsers.concat(batch); } @@ -172,11 +167,9 @@ Groups.getOwnersAndMembers = async function (groupName, uid, start, stop) { if (stop === -1) { await addMembers(memberStart, -1); } else { - while (returnUsers.length < countToReturn && !done) { + while (returnUsers.length < countToReturn) { /* eslint-disable no-await-in-loop */ await addMembers(memberStart, memberStop); - memberStart += countToReturn; - memberStop += countToReturn; } } diff --git a/src/routes/debug.js b/src/routes/debug.js index 0370a30a26..460534fcdc 100644 --- a/src/routes/debug.js +++ b/src/routes/debug.js @@ -6,25 +6,8 @@ var nconf = require('nconf'); module.exports = function (app) { var router = express.Router(); - router.get('/test', async function (req, res) { - // res.redirect(404); - const groups = require('../groups'); - - // const d1 = await groups.getOwnersAndMembers('GNU/Linux User', 1, 0, 9); - // const d2 = await groups.getOwnersAndMembers('GNU/Linux User', 1, 10, 19); - // const d3 = await groups.getOwnersAndMembers('GNU/Linux User', 1, 0, 19); - const d4 = await groups.getOwnersAndMembers('GNU/Linux User', 1, 45, 51); - - - // const uids1 = d1.map(d => d.uid); - // const uids2 = d2.map(d => d.uid); - res.json({ - // uids1: uids1, - // uids2: uids2, - // uids3: d3.map(d => d.uid), - uids4: d4.map(d => d.uid), - len4: d4.length, - }); + router.get('/test', function (req, res) { + res.redirect(404); }); app.use(nconf.get('relative_path') + '/debug', router);