Skip to content

Commit

Permalink
fix: avoid unnecessary query to the db
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorGoryany committed Sep 6, 2024
1 parent 3e00c4f commit 461ad9d
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions trpc/queries/goals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,21 @@ export const goalsFilter = async (
},
};

const criteriaGoalIds = await prisma.goalAchieveCriteria.findMany({
where: {
criteriaGoalId: { not: null },
},
select: {
criteriaGoalId: true,
},
});
let criteriaFilter: Prisma.GoalFindManyArgs['where'] = {};

const criteriaFilter: Prisma.GoalFindManyArgs['where'] = data.hideCriteria
? {
id: { not: { in: criteriaGoalIds.map(({ criteriaGoalId }) => criteriaGoalId) as string[] } },
}
: {};
if (data.hideCriteria) {
const criteriaGoalIds = await prisma.goalAchieveCriteria.findMany({
where: {
criteriaGoalId: { not: null },
},
select: {
criteriaGoalId: true,
},
});
criteriaFilter = {
id: { not: { in: criteriaGoalIds.map(({ criteriaGoalId }) => criteriaGoalId) as string[] } },
};
}

const orderBy: any = [];

Expand Down

0 comments on commit 461ad9d

Please sign in to comment.