From ef889373366777ce204874a11e7ff190d353f3ca Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Sat, 26 Jul 2025 21:39:22 +0000 Subject: [PATCH] fetch all recipes in one request instead of multiple --- .../Domain/Recipe/RecipeTimeline.vue | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/frontend/components/Domain/Recipe/RecipeTimeline.vue b/frontend/components/Domain/Recipe/RecipeTimeline.vue index 49ed1694d..92317d168 100644 --- a/frontend/components/Domain/Recipe/RecipeTimeline.vue +++ b/frontend/components/Domain/Recipe/RecipeTimeline.vue @@ -242,28 +242,28 @@ export default defineNuxtComponent({ alert.success(i18n.t("events.event-deleted") as string); }; - async function getRecipe(recipeId: string): Promise { - const { data } = await api.recipes.getOne(recipeId); - return data; + async function getRecipes(recipeIds: string[]): Promise { + const qf = "id IN [" + recipeIds.map((id) => `"${id}"`).join(", ") + "]"; + const { data } = await api.recipes.getAll(1, -1, { queryFilter: qf }) + return data?.items || []; }; async function updateRecipes(events: RecipeTimelineEventOut[]) { - const recipePromises: Promise[] = []; - const seenRecipeIds: string[] = []; + const recipeIds: string[] = []; events.forEach((event) => { - if (seenRecipeIds.includes(event.recipeId) || recipes.has(event.recipeId)) { + if (recipeIds.includes(event.recipeId) || recipes.has(event.recipeId)) { return; } - seenRecipeIds.push(event.recipeId); - recipePromises.push(getRecipe(event.recipeId)); + recipeIds.push(event.recipeId); }); - const results = await Promise.all(recipePromises); + const results = await getRecipes(recipeIds); results.forEach((result) => { - if (result && result.id) { - recipes.set(result.id, result); + if (!result?.id) { + return; } + recipes.set(result.id, result); }); }