mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +00:00
Optimized nested recipe resolving / prevent infinite nested recipes
This commit is contained in:
parent
5d98140843
commit
039ed54a58
@ -11,9 +11,31 @@ AS (
|
|||||||
SELECT rn.recipe_id, r1.includes_recipe_id, rn.servings
|
SELECT rn.recipe_id, r1.includes_recipe_id, rn.servings
|
||||||
FROM recipes_nestings rn, r1 r1
|
FROM recipes_nestings rn, r1 r1
|
||||||
WHERE rn.includes_recipe_id = r1.recipe_id
|
WHERE rn.includes_recipe_id = r1.recipe_id
|
||||||
LIMIT 1000000000 -- This is just a safety limit to prevent infinite loops due to infinite nested recipes
|
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
*,
|
*,
|
||||||
1 AS id -- Dummy, LessQL needs an id column
|
1 AS id -- Dummy, LessQL needs an id column
|
||||||
FROM r1;
|
FROM r1;
|
||||||
|
|
||||||
|
CREATE TRIGGER prevent_self_nested_recipes_INS BEFORE INSERT ON recipes_nestings
|
||||||
|
BEGIN
|
||||||
|
SELECT CASE WHEN((
|
||||||
|
SELECT 1
|
||||||
|
FROM recipes_nestings
|
||||||
|
WHERE NEW.recipe_id = NEW.includes_recipe_id
|
||||||
|
)
|
||||||
|
NOTNULL) THEN RAISE(ABORT, "Recursive nested recipe detected") END;
|
||||||
|
END;
|
||||||
|
|
||||||
|
CREATE TRIGGER prevent_self_nested_recipes_UPD BEFORE UPDATE ON recipes_nestings
|
||||||
|
BEGIN
|
||||||
|
SELECT CASE WHEN((
|
||||||
|
SELECT 1
|
||||||
|
FROM recipes_nestings
|
||||||
|
WHERE NEW.recipe_id = NEW.includes_recipe_id
|
||||||
|
)
|
||||||
|
NOTNULL) THEN RAISE(ABORT, "Recursive nested recipe detected") END;
|
||||||
|
END;
|
||||||
|
|
||||||
|
DELETE FROM recipes_nestings
|
||||||
|
WHERE recipe_id = includes_recipe_id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user