fix(challenge export): do not fetch users and tasks concurrently

This commit is contained in:
Matteo Pagliazzi
2019-11-02 12:43:51 +01:00
parent 6e9ab1dbbb
commit 4d88787ba0

View File

@@ -591,21 +591,22 @@ api.exportChallengeCsv = {
// computation on MongoDB but then iterated through all
// results on the server so the perf difference isn't that big (hopefully)
const [members, tasks] = await Promise.all([
User.find({ challenges: challengeId })
.select(nameFields)
.sort({ _id: 1 })
.lean() // so we don't involve mongoose
.exec(),
const members = await User
.find({ challenges: challengeId })
.select(nameFields)
.sort({ _id: 1 })
.lean() // so we don't involve mongoose
.exec();
Tasks.Task.find({
const tasks = Tasks.Task
.find({
'challenge.id': challengeId,
userId: { $exists: true },
}).sort({ userId: 1, text: 1 })
.select('userId type text value notes streak')
.lean()
.exec(),
]);
})
.sort({ userId: 1, text: 1 })
.select('userId type text value notes streak')
.lean() // so we don't involve mongoose
.exec();
let resArray = members
.map(member => [member._id, member.profile.name, member.auth.local.username]);