Why is django slowly generating selection fields for foreign keys?

I have an administrator view that contains four foreign keys, each of which contains several thousand entries. It slowly appears in the browser.

If I change the django model to exclude selection fields by adding raw_id_fields, everything will become nice and fast. Thus, the slowness is due to a set of selective drops, and this is a known problem, because that is why raw_id_fields exist.

I would like to understand what causes slowness. On the server, if I make an SQL query for the data that is used to populate the selection fields, the results are instantaneous. Therefore, Postgres retrieves or sorts data is not the cause.

Perhaps this is the time required to transfer the data filling in the drop-down lists? Or is it something that django does?

+3
source share
2 answers

Transferring huge selection lists takes a lot of time. The markup can really start to add up. Try to check how big your html output is in KB / MB. I remember once having seen a selection list (several thousand records), I was inflating a page to 5 or so megabytes on the previous task. This was in an ASP.NET project; it really doesn't matter which framework you use when you have such a problem.

, django , , , , .

+8

Source: https://habr.com/ru/post/1707116/


All Articles