E
E
Egor Kazantsev2015-07-28 14:42:39
Django
Egor Kazantsev, 2015-07-28 14:42:39

How to overclock Django ORM?

I created a model and there are a lot of ForeignKey in it. And apparently the ORM creates some kind of Joins and because of this, everything is bad with the return speed. What are some good ways to optimize? Do not offer to overclock the database - it is already all in memory.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
sim3x, 2015-07-28
@saintbyte

Bring your models to 3 normal form
Then cache the answer
Then "overclock the orm"

U
un1t, 2015-07-28
@un1t

install django-debug-toolbar and profile requests using prefetch_related

E
emacsway, 2015-11-27
@emacsway

Correctly told - it is necessary to profile requests. First you need to establish the cause. Find a brake request, check indexes, look in EXPLAIN. In my experience, Django ORM sometimes creates such queries (for example, an exception through a subquery, etc.) that the only acceptable solution is not to use the Django query builder, but to use Raw-SQL. However, I am not a big supporter of Raw-SQL , and in this case this library often helps me out for building SQL queries . If many single requests are made by links, then prefetch_related().

A
Artem Klimenko, 2015-07-28
@aklim007

djbook.ru/rel1.8/topics/db/optimization.html
https://docs.djangoproject.com/en/1.8/topics/db/op...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question