Improve relation choices limiting (using html_cutoff) by blag · Pull Request #3877 · encode/django-rest-framework (original) (raw)
When we're showing the HTML form field for related objects and we're trying to generate the choices for the select field, it doesn't seem to make sense to grab every single record in a table, only to display html_cutoff
(default: 1000) of them and completely ignore the rest.
Instead, we should limit the number of objects we want from the database to the number of objects we're planning on displaying. This changeset makes the semantics of retrieving related objects the same as for displaying related objects. In other words, we limit the queryset to the first html_cutoff
objects. That way we aren't pulling back more objects than necessary, because this can kill performance for tables with "lots" of records (~500k in my case, ~400k for others).
Closes #3329.