Reputation: 15620
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)
Upvotes: 2
Views: 815
Reputation: 51715
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:
Notice:
Upvotes: 1