Bird
0
0

You want to optimize a query that fetches users and their posts but only want posts created in the last 7 days. Which approach is best?

hard📝 Conceptual Q8 of 15
Flask - Performance Optimization
You want to optimize a query that fetches users and their posts but only want posts created in the last 7 days. Which approach is best?
AUse joinedload() with a custom query option to filter posts by date
BUse lazy loading and filter posts after fetching users
CUse limit() on users and ignore posts filtering
DFetch posts separately and join in Python code
Step-by-Step Solution
Solution:
  1. Step 1: Understand filtering related objects in eager loading

    joinedload() can be combined with custom options to filter related posts at the database level.
  2. Step 2: Compare alternatives

    Lazy loading delays queries causing inefficiency; limit() ignores posts; fetching separately adds complexity.
  3. Final Answer:

    Use joinedload() with a custom query option to filter posts by date -> Option A
  4. Quick Check:

    Filter related data in query with joinedload = D [OK]
Quick Trick: Filter related data inside joinedload() for best performance [OK]
Common Mistakes:
MISTAKES
  • Filtering related data in Python instead of query
  • Using lazy loading causing many queries
  • Ignoring filtering on related objects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes