Skip to content

Commit

Permalink
Fix Crash on Event with Empty Recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
T3C42 committed Nov 8, 2024
1 parent 04a94ed commit fec5824
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
36 changes: 36 additions & 0 deletions foodlib/migrations/20241108122437_fix_recipe_name_null.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-- Add migration script here
CREATE OR REPLACE VIEW public.event_ingredients_before_prep_time_resolve AS
SELECT events.event_id,
events.event_name AS event,
event_meals.recipe_id,
recipes.name as recipe,
event_meals.place_id,
places.name AS place,
event_meals.start_time,
event_meals.end_time,
resolved_recipes.ingredient_id,
resolved_recipes.ingredient,
resolved_recipes.weight * recipe_multipliers.recipe_multiplier * ingredient_weight.weight AS weight,
recipe_multipliers.recipe_multiplier * resolved_recipes.weight * ingredients.energy * 1000::numeric AS energy,
ingredient_sources.price * (recipe_multipliers.recipe_multiplier * resolved_recipes.weight / (ingredient_weight.weight * COALESCE(ingredient_sources.package_size, 1::numeric)))::double precision AS price,
event_meals.servings,
event_meals.meal_id,
resolved_recipes.acc AS subrecipe_hierarchy,
event_meals.start_time AS buy_by,
ingredient_sources.store_id
FROM events
LEFT JOIN event_meals USING (event_id)
LEFT JOIN places USING (place_id)
LEFT JOIN resolved_recipes USING (recipe_id)
LEFT JOIN recipes USING (recipe_id)
LEFT JOIN ingredients USING (ingredient_id)
LEFT JOIN best_event_ingredient_sources USING (event_id, ingredient_id)
LEFT JOIN ingredient_sources USING (ingredient_source_id, ingredient_id)
LEFT JOIN ingredient_weight USING (ingredient_id, unit_id)
LEFT JOIN ( SELECT event_meals_1.recipe_id,
event_meals_1.event_id,
event_meals_1.place_id,
event_meals_1.start_time,
event_meals_1.energy_per_serving * event_meals_1.servings::numeric / recipe_stats.energy AS recipe_multiplier
FROM event_meals event_meals_1
JOIN recipe_stats USING (recipe_id)) recipe_multipliers USING (event_id, recipe_id, place_id, start_time)
12 changes: 6 additions & 6 deletions foodlib/src/meals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ impl FoodBase {
place as "place!",
event_meals.start_time as "start_time!",
event_meals.end_time as "end_time!",
round(sum(weight),2) as "weight!",
(CASE WHEN event_meals.servings != 0 THEN round(sum(energy) / event_meals.servings,0) ELSE 0 END) as "energy!",
sum(price) as "price!",
COALESCE(round(sum(weight),2),0) as "weight!",
COALESCE((CASE WHEN event_meals.servings != 0 THEN round(sum(energy) / event_meals.servings,0) ELSE 0 END),0) as "energy!",
COALESCE(sum(price),'0'::float8::numeric::money) as "price!",
event_meals.servings as "servings!"
FROM event_ingredients
Expand Down Expand Up @@ -109,9 +109,9 @@ impl FoodBase {
place as "place!",
event_meals.start_time as "start_time!",
event_meals.end_time as "end_time!",
round(sum(weight),2) as "weight!",
(CASE WHEN event_meals.servings != 0 THEN round(sum(energy) / event_meals.servings,0) ELSE 0 END) as "energy!",
sum(price) as "price!",
COALESCE(round(sum(weight),2),0) as "weight!",
COALESCE((CASE WHEN event_meals.servings != 0 THEN round(sum(energy) / event_meals.servings,0) ELSE 0 END),0) as "energy!",
COALESCE(sum(price),'0'::float8::numeric::money) as "price!",
event_meals.servings as "servings!"
FROM event_ingredients
Expand Down

0 comments on commit fec5824

Please sign in to comment.