diff --git a/packages/trpc/src/dbHelpers/getRecipesWithConstraints.ts b/packages/trpc/src/dbHelpers/getRecipesWithConstraints.ts index 6c7c07d95..541c24739 100644 --- a/packages/trpc/src/dbHelpers/getRecipesWithConstraints.ts +++ b/packages/trpc/src/dbHelpers/getRecipesWithConstraints.ts @@ -25,12 +25,15 @@ export const getRecipesWithConstraints = async (args: { offset, limit, recipeIds: filterByRecipeIds, - labels, + labels: _labels, labelIntersection, ratings, recipeIds, } = args; + const labels = _labels?.filter((label) => label !== "unlabeled"); + const mustBeUnlabeled = !!_labels?.includes("unlabeled"); + let friends: Set = new Set(); if (contextUserId) { const friendships = await getFriendshipIds(contextUserId); @@ -145,7 +148,21 @@ export const getRecipesWithConstraints = async (args: { where.AND.push({ id: { in: filterByRecipeIds } }); } - if (labels && labelIntersection) { + if (mustBeUnlabeled) { + where.AND.push({ + recipeLabels: { + none: { + label: { + userId: { + in: userIds, // We do this rather than none:{} due to Prisma perf issues... + }, + }, + }, + }, + }); + } + + if (labels?.length && labelIntersection) { where.AND.push( ...labels.map( (label) => @@ -162,7 +179,7 @@ export const getRecipesWithConstraints = async (args: { ); } - if (labels && !labelIntersection) { + if (labels?.length && !labelIntersection) { where.AND.push({ recipeLabels: { some: {