Skip to content

Commit

Permalink
fix: improve votation fetch performance
Browse files Browse the repository at this point in the history
  • Loading branch information
edalholt committed Sep 27, 2023
1 parent 5c06380 commit 824da5d
Showing 1 changed file with 4 additions and 27 deletions.
31 changes: 4 additions & 27 deletions backend/controllers/votation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,7 @@ export async function getAllVotations(req: RequestWithNtnuiNo, res: Response) {
continue;
}

const optionList: OptionType[] = [];

for (const optionID of vote.options) {
const id = optionID;
const option = await Option.findById(id);
if (option) {
const newOption = new Option({
_id: id,
title: option.title,
voteCount: option.voteCount,
});
optionList.push(newOption);
}
}
const optionList = await Option.find({ _id: { $in: vote.options } });

let isActive = false;
if (assembly.currentVotation) {
Expand Down Expand Up @@ -142,19 +129,9 @@ export async function getCurrentVotation(
return res.status(200).json(null);
}

const optionList: LimitedOptionType[] = [];

for (const optionID of vote.options) {
const id = optionID;
const option = await Option.findById(id);
if (option) {
const newOption: LimitedOptionType = {
_id: id,
title: option.title,
};
optionList.push(newOption);
}
}
const optionList: LimitedOptionType[] = await Option.find({
_id: { $in: vote.options },
}).select("_id title");

const votationResponse: LimitedVoteResponseType = {
_id: assembly.currentVotation,
Expand Down

0 comments on commit 824da5d

Please sign in to comment.