Django response time issues

Hi, I have many objects that I get from the request, the request is not evaluated yet, when I pass the object list to the paginator object, it took 14 seconds to return the paginator object, because it evaluates all the objects in the list, it took time (db hit may be).

I forcefully evaluated the request before sending it to the paginator object as:

ds_objects = list(ds_objects) 

Guess that now the paging reference point takes 0.0 seconds in the returned object, but the problem still remains all the time taken by ds_objects = list (ds_objects), how can I do this efficiently so that the response time of my view is reduced to 2 or 3 seconds? I did not find a better solution: s

+4
source share
1 answer

I assume that JOINs (so select_related ) are not important for query speed. In any case, when you execute the values() query, you really don't need select_related , because only the fields you will ever get are those that are specified as values() arguments, and they are still retrieved by JOIN.

To understand why this takes so long, you can do the following:

Print "raw sql" with

 print tbl_action_log.objects.order_by('-TicketID', '-ActionLogID').query 

Modify it (it is not actually SQL, but it should be enough), which will be run in the SQL client, for example django own manage.py dbshell .

Run it, pay attention to the time. Then execute EXPLAIN ... (put your query in points), you will probably see the message "full table scan"

Add the appropriate index to the database table, by the affected columns, and run the query again. The index will probably be as follows:

 CREATE INDEX idx_action_log_on_tkid_logid ON tbl_action_log (TicketID, ActionLogID); 

When you are satisfied with the index, save its creation collection to the app/sql/modelname.sql , this will create the index in any new deployment.

+1
source

All Articles