Changes between Initial Version and Version 1 of Ticket #27001, comment 3


Ignore:
Timestamp:
Aug 2, 2016, 10:30:39 PM (8 years ago)
Author:
Alex Hill

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #27001, comment 3

    initial v1  
    11Created a pull request with a fix.
    22
    3 `ChoiceFieldRenderer` doesn't have `__iter__` defined, so Python iterates over it by calling `__getitem__` with an increasing index until an exception is raised. `ChoiceFieldRenderer.__getitem__` calls `list` on itself, which turns iteration into an n^2 operation. When the choices are backed by a queryset as in ModelChoiceField, that means lots of redundant database queries.
     3`ChoiceFieldRenderer` doesn't have `__iter__` defined, so Python iterates over it by calling `__getitem__` with an increasing index until an exception is raised. `ChoiceFieldRenderer.__getitem__` calls `list` on itself, which turns iteration into an n^2^ operation. When the choices are backed by a queryset as in ModelChoiceField, that means lots of redundant database queries.
    44
    55Fixed by adding an `__iter__` method to `ChoiceFieldRenderer` and changing `__getitem__` to use it, so that indexing still works.
Back to Top