Skip to content
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 and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit selects #3313

Merged
merged 4 commits into from
Aug 21, 2015
Merged

Limit selects #3313

merged 4 commits into from
Aug 21, 2015

Conversation

tomchristie
Copy link
Member

Closes #3309.

@tomchristie tomchristie added this to the 3.2.3 Release milestone Aug 21, 2015
tomchristie added a commit that referenced this pull request Aug 21, 2015
Limit rendering of relational selects to max 1000 items by default.
@tomchristie tomchristie merged commit f601c6c into master Aug 21, 2015
@tomchristie tomchristie deleted the limit-selects branch August 21, 2015 10:41
@rubendura
Copy link
Contributor

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.

@tomchristie
Copy link
Member Author

@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?

@rubendura
Copy link
Contributor

Yes, DRF is updated to 3.2.3

On 25 Aug 2015, at 14:36, Tom Christie [email protected] wrote:

@rubendura https://github.com/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?


Reply to this email directly or view it on GitHub #3313 (comment).

@tomchristie
Copy link
Member Author

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

image

Given that I can't reproduce the issue you're seeing I'd need you to narrow this down to a simple replicable case.

@rubendura
Copy link
Contributor

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.

@tomchristie
Copy link
Member Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants