Skip to content

Only preload selected options for APISelect widgets #3812

Closed
@hSaria

Description

@hSaria

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions