Limit selects by tomchristie · Pull Request #3313 · encode/django-rest-framework (original) (raw)
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation6 Commits4 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
tomchristie added a commit that referenced this pull request
Limit rendering of relational selects to max 1000 items by default.
Is this really working as it should? I've got a PrimaryKeyRelatedField and the html_cutoff parameter is being ignored (using either the default value or a smaller one).
That relation spans thousands of rows, so that page is impossible to load. Setting the style as suggested in the docs to input.html does the trick, but the dropdown is still unusable.
I tried setting the cutoff to 20 just to test it and I can't see any change, it took forever.
@rubendura Just gave it a try myself for sanity and I'm not seeing any problems with it - working just fine. You've updated to 3.2.3 right?
I really can't replicate this...
git clone https://github.com/tomchristie/basic-rest-framework.git example
cd example
virtualenv env
source env/bin/activate
pip install -r ./requirements.txt
python manage.py migrate
python manage.py shell
> from django.contrib.auth.models import Group
> for i in range(10000):
> Group.objects.create(name='Group%d' % i)
> exit
python manage.py runserver
Given that I can't reproduce the issue you're seeing I'd need you to narrow this down to a simple replicable case.
I think I've found the root of my issue.
RelatedField.choices seems to ignore html_cutoff when building the returned OrderedDict. My queryset at that point contains ~400k items. I'm running my test system inside a vagrant machine and it looks like while performing this operation I run out of memory in that machine, thus the slowness. Actually the process is being killed after some time with no response.
Is it possible to limit the number of items being used inside RelatedField.choices? Maybe slice the queryset using html_cutoff before creating the OrderedDict.
Okay that makes sense - could you open this as a new issue 'Improve relation choices limiting' or similar? If you could also point to exactly where it's failing that'd be helpful. Thanks so much!
This was referenced
Mar 9, 2017
This was referenced
Oct 6, 2017
This was referenced
Oct 16, 2017
2 participants