Skip to content

N+1 queries and potential infinite loop in GetNodeAncestors #42

@windoze95

Description

@windoze95

Location: internal/repository/recipe_tree.go:114-131

Ancestor traversal performs one DB query per ancestor (N+1 pattern) and has no cycle detection. If data has a cycle (node A parent is B, B parent is A), the loop runs forever. Additionally, append([]models.RecipeNode{node}, ancestors...) is O(n) per iteration making it O(n^2) overall.

Fix: use a recursive CTE query, add a max depth limit, and append-then-reverse.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions