Performance: Relationships (one-to-many)
MEDIUM IMPACT
This affects how data is loaded and rendered on the page, impacting load speed and responsiveness when displaying related records.
from sqlalchemy.orm import joinedload parents = Parent.query.options(joinedload(Parent.children)).all() for parent in parents: children = parent.children # Loads parents and children in a single query
parents = Parent.query.all() for parent in parents: children = [child for child in parent.children] # This triggers a separate database query for each parent due to lazy loading
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Lazy loading (N+1 queries) | Minimal DOM nodes initially | Multiple reflows if data loads incrementally | Higher paint cost due to delayed content | [X] Bad |
| Eager loading (single query) | All DOM nodes ready at once | Single reflow after full data load | Lower paint cost with faster content display | [OK] Good |