Bird
0
0

How can you combine lazy loading and eager loading in Flask-SQLAlchemy to optimize performance for a User with many posts but only occasionally access comments on posts?

hard📝 component behavior Q9 of 15
Flask - Performance Optimization
How can you combine lazy loading and eager loading in Flask-SQLAlchemy to optimize performance for a User with many posts but only occasionally access comments on posts?
ASet posts to lazy='select' and comments to lazy='joined'.
BSet posts to lazy='joined' and comments to lazy='select'.
CSet both posts and comments to lazy='dynamic'.
DSet posts to lazy='noload' and comments to lazy='select'.
Step-by-Step Solution
Solution:
  1. Step 1: Apply eager loading to frequently accessed data

    Set posts to lazy='joined' to load them immediately with users.
  2. Step 2: Use lazy loading for less frequent data

    Set comments to lazy='select' to load only when accessed, saving resources.
  3. Final Answer:

    Set posts to lazy='joined' and comments to lazy='select'. -> Option B
  4. Quick Check:

    Combine eager for frequent, lazy for occasional data [OK]
Quick Trick: Eager load frequent, lazy load occasional relationships [OK]
Common Mistakes:
MISTAKES
  • Eager loading everything causing slow queries
  • Lazy loading all causing many queries
  • Using lazy='dynamic' unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes