fix: #8154, move start/stop every iteration

v1.18.x
Barış Soner Uşaklı 5 years ago
parent 690bb69d03
commit 300c04cef9

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

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

Loading…
Cancel
Save