Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
Django store aggregated data in the database?

I have a use case where I have some complex functions (involving aggregations) that take a few seconds to run, and are affecting the UX of the app (even when the rows are just about 25-30k and the relevant fields are indexed). I am thinking of storing the aggregations in the database itself (and run them nightly) since real-time-liness of the data is not very important here. Is that a common practice with Django?

(I couldnt find much discussion on that on SO though)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Do you have several options:

  • @ittus's and @Andrey Shipilov's approach: store result in cache system like Memcache or redis. You can check github.com/niwinz/django-redis

  • @Anonymous's approach: use some sort of materialized view (depends on your db), and then create a unmanaged model in django to query it.

  • Create new models/fields for aggregate data and figure up it nightly though a django custom comand or a celery task.

Conclusions:

  • Your question should be close because is a primarily opinion-based question, like this one Django - what is best practice - Calculating field values.

Notice:

  • If you need real time calculation then you can overwrite save method on models to keep data or just connect a post_save signal.
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!