Skip to content

Only preload selected options for APISelect widgets #3812

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

Closed
hSaria opened this issue Jan 1, 2020 · 2 comments · Fixed by #3813
Closed

Only preload selected options for APISelect widgets #3812

hSaria opened this issue Jan 1, 2020 · 2 comments · Fixed by #3813
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@hSaria
Copy link
Contributor

hSaria commented Jan 1, 2020

Proposed Changes

Change APISelect and APISelectMultiple to only preload the selected fields.

Justification

The current implementation for APISelect and APISelectMultiple preloads all of the objects of the model. Even though paging of size 50 is performed on the API calls, the page will load with all of the objects, even ignoring what APISelect might be filtering out.

For example, all of the roles (11 through 99) are loaded in the device creation page. The APISelect itself paginates correctly, but I presume the default behavior of Django's forms.Select is making it so all of the options are loaded (not 100% sure about the last part).

<select name="device_role" class="netbox-select2-api form-control select2-hidden-accessible" data-url="/api/dcim/device-roles/" required="" placeholder="Device role" id="id_device_role" tabindex="-1" aria-hidden="true">
  <option value="" selected="">---------</option>
  <option value="11">role-11</option>
  <option value="12">role-12</option>
  <option value="13">role-13</option>  
...
  <option value="97">role-97</option>
  <option value="98">role-98</option>
  <option value="99">role-99</option>
</select>

By preventing those options from being loaded, the pages that use the APISelect and/or APISelectMultiple would load faster due to smaller pages.

It should be noted that selected options must be loaded in order for them to be rendered on the form. It's only the options that aren't selected which can be omitted as they are created dynamically when selected.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application labels Jan 2, 2020
@jeremystretch
Copy link
Member

Thanks for capturing this. It's something I've been wanting to address for a while now.

@hSaria
Copy link
Contributor Author

hSaria commented Jan 2, 2020

It's really @DanSheps that should be thanked. He pointed out the inefficiency when I was working on #3814

jeremystretch added a commit that referenced this issue Jan 2, 2020
Fixes #3812: Only preload selected options for API-based select
@lock lock bot locked as resolved and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants