Skip to content

Commit

Permalink
improve filter performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-vS committed Jun 2, 2024
1 parent e32aa36 commit 1aa0428
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 6 additions & 7 deletions app/opportunities/[opportunity_id]/review/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ export default async function StartReview({ params }: StartReviewProps) {
);

// User has not reviewed questionnaire and application together
const hasNotReviewed =
questionnaire.reviews.filter(
(review) =>
review.userId === session.user.id &&
review.questionnaireId === questionnaire.id &&
review.applicationId === application.id,
).length === 0;
const hasNotReviewed = !questionnaire.reviews.some(
(review) =>
review.userId === session.user.id &&
review.questionnaireId === questionnaire.id &&
review.applicationId === application.id,
);

const lessReviewsThanRequired =
questionnaire.reviews.filter(
Expand Down
4 changes: 3 additions & 1 deletion lib/faker/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ function generateTallyData(): TallyData {
formId: faker.string.nanoid(6),
formName: faker.science.chemicalElement().name,
createdAt: now.toISOString(),
fields: Array.from({ length: 2 }, () => generateTallyField()),
fields: Array.from({ length: faker.number.int({ min: 3, max: 6 }) }, () =>
generateTallyField(),
),
};
}

Expand Down

0 comments on commit 1aa0428

Please sign in to comment.