1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-05 05:25:26 +02:00

fix: Optimize Recipe Timeline Requests (#5811)

This commit is contained in:
Michael Genson 2025-07-28 06:25:49 -05:00 committed by GitHub
parent 675ac9c32b
commit a087760d53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 13 deletions

View file

@ -242,28 +242,28 @@ export default defineNuxtComponent({
alert.success(i18n.t("events.event-deleted") as string);
};
async function getRecipe(recipeId: string): Promise<Recipe | null> {
const { data } = await api.recipes.getOne(recipeId);
return data;
async function getRecipes(recipeIds: string[]): Promise<Recipe[]> {
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<Recipe | null>[] = [];
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);
});
}