Revert "fix: #8154, move start/stop every iteration"

This reverts commit 300c04cef9.
v1.18.x
Barış Soner Uşaklı 5 years ago
parent 300c04cef9
commit 4abe5eb7ff

@ -154,17 +154,12 @@ Groups.getOwnersAndMembers = async function (groupName, uid, start, stop) {
} }
}); });
let done = false;
let returnUsers = owners; let returnUsers = owners;
let memberStart = start - ownerUids.length + 1; const memberStart = Math.max(0, start - ownerUids.length + 1);
let memberStop = memberStart + countToReturn - 1; const memberStop = memberStart + countToReturn;
memberStart = Math.max(0, memberStart);
memberStop = Math.max(0, memberStop);
async function addMembers(start, stop) { async function addMembers(start, stop) {
let batch = await user.getUsersFromSet('group:' + groupName + ':members', uid, 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())); batch = batch.filter(user => user && user.uid && !ownerUids.includes(user.uid.toString()));
returnUsers = returnUsers.concat(batch); returnUsers = returnUsers.concat(batch);
} }
@ -172,11 +167,9 @@ Groups.getOwnersAndMembers = async function (groupName, uid, start, stop) {
if (stop === -1) { if (stop === -1) {
await addMembers(memberStart, -1); await addMembers(memberStart, -1);
} else { } else {
while (returnUsers.length < countToReturn && !done) { while (returnUsers.length < countToReturn) {
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
await addMembers(memberStart, memberStop); await addMembers(memberStart, memberStop);
memberStart += countToReturn;
memberStop += countToReturn;
} }
} }

@ -6,25 +6,8 @@ var nconf = require('nconf');
module.exports = function (app) { module.exports = function (app) {
var router = express.Router(); var router = express.Router();
router.get('/test', async function (req, res) { router.get('/test', function (req, res) {
// res.redirect(404); 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,
});
}); });
app.use(nconf.get('relative_path') + '/debug', router); app.use(nconf.get('relative_path') + '/debug', router);

Loading…
Cancel
Save