Tips to reduce query bottlenecks - Deepstash

Explore the World's Best Ideas

Join today and uncover 100+ curated journeys from 50+ topics. Unlock access to our mobile app with extensive features.

Tips to reduce query bottlenecks

Tips to reduce query bottlenecks

  1. Reduce number of queries
  2. Speed up common queries
  3. Cache results of heavy queries
  4. Turn off ATOMIC_REQUESTS -- This settings makes all queries run in a transaction. Read Django docs before changing it to understand the trade-offs.
  5. Tune database settings

3

33 reads

MORE IDEAS ON THIS

Reduce number of queries

Reduce number of queries

  • Use select_related() to retrieve Foreign Key relations in the same query.
  • Use prefetch_related() for many-to-many and many-to-one relations.
  • Re-use query results across the lifetime of the request if you need them in more pla...

3

24 reads

Speed up common queries

Speed up common queries

  • Add indexes on fields you frequently filter/sort on.
  • Analyze query plans generated by common queries and identify bottlenecks.
  • Rewrite queries to return smaller results sets when possible.
  • Re-model data

3

11 reads

Finding query bottlenecks

Finding query bottlenecks

Review your API endpoints and views for:

  • Duplicate queries
  • Slow queries
  • ORM calls that resolve more queries than you expect

3

49 reads

CURATED FROM

IDEAS CURATED BY

ocpodariu

Alt account of @ocp. I use it to stash ideas about software engineering

📖 Two Scoops of Django

“

Read & Learn

20x Faster

without
deepstash

with
deepstash

with

deepstash

Personalized microlearning

—

100+ Learning Journeys

—

Access to 200,000+ ideas

—

Access to the mobile app

—

Unlimited idea saving

—

—

Unlimited history

—

—

Unlimited listening to ideas

—

—

Downloading & offline access

—

—

Supercharge your mind with one idea per day

Enter your email and spend 1 minute every day to learn something new.

Email

I agree to receive email updates