Managing unused foods #3551
Unanswered
AstroPhotoJay
asked this question in
Q&A
Replies: 1 comment 1 reply
-
While there isn't a way to do it in-app, you can use the API for this. Make sure to backup your data before doing this, though. Some pseudo Python code: # Get all foods used in recipes
seen_foods = set()
recipes_data = client.get("/recipes", params={"perPage": -1})
for recipe_summary in recipes_data.items:
slug = recipe_summary["slug"]
recipe = client.get(f"/recipe/{slug}")
for ing in recipe["recipeIngredient"]:
if ing["food"]:
seen_foods.add(ing["food"]["id"])
# Get all foods and store any that were not seen in a recipe
unused_foods = set()
foods_data = client.get("/foods", params={"perPage": -1})
for food in foods_data.items:
if food["id"] not in seen_foods:
unused_foods.add(food["id"])
# Delete all unseen foods
for food_id in unused_foods:
client.delete(f"/foods/{food_id}") |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When setting up mealie, I seeded the food database with the default data provided by mealie. I now find myself wanting to use the food filter more often, however there are a large number of unused foods for which I can search which provides a null search result. Screenshot below.
Is there any way to delete unused foods or hide unused foods from the food search dropdown?
If not, would deleting and reimporting all recopies also import the necessary food items?
Any help gratefully appreciated.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions