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

N+1 issue on the /api/ipam/ip-addresses/ endpoint #15845

Closed
mulmat opened this issue Apr 25, 2024 · 6 comments · Fixed by #15886
Closed

N+1 issue on the /api/ipam/ip-addresses/ endpoint #15845

mulmat opened this issue Apr 25, 2024 · 6 comments · Fixed by #15886
Assignees
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@mulmat
Copy link
Contributor

mulmat commented Apr 25, 2024

Deployment Type

Self-hosted

NetBox Version

v3.7.6

Python Version

3.10

Steps to Reproduce

Call the /api/ipam/ip-addresses/ endpoint with more than 1 assigned ip address in the database (important that the ip addresses are assigned and you are listing assigned ip addresses, for example by using assigned_to_interface=true filter)

Expected Behavior

No N+1 issue.

I can submit I PR if wanted (I think the issue is that IPAddressViewSet are missing assigned_object_type in the prefetch_related)

Observed Behavior

N+1 issue with the following query:

SELECT ••• FROM "django_content_type" WHERE "django_content_type"."id" = X LIMIT 21

@mulmat mulmat added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Apr 25, 2024
@jeremystretch
Copy link
Member

Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v3.7.6. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.

@jeremystretch jeremystretch removed their assignment Apr 25, 2024
@jeremystretch jeremystretch added status: revisions needed This issue requires additional information to be actionable and removed status: needs triage This issue is awaiting triage by a maintainer labels Apr 25, 2024
@mulmat
Copy link
Contributor Author

mulmat commented Apr 25, 2024

@jeremystretch - forgot to mention that the ips must be assigned. I've updated the post now above + also verified that the issue also affects 3.7.6

As a reference, I created ips like this to reproduce the issue:

IPAddress.objects.create(
    address=ip,
    assigned_object_type=ContentType.objects.get(app_label="dcim", model="interface"),
    assigned_object_id=52,
)

@jeremystretch jeremystretch added status: under review Further discussion is needed to determine this issue's scope and/or implementation status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: low Does not significantly disrupt application functionality, or a workaround is available and removed status: revisions needed This issue requires additional information to be actionable status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Apr 25, 2024
@mulmat
Copy link
Contributor Author

mulmat commented Apr 29, 2024

@jeremystretch - I can fix a PR for this

@jeremystretch
Copy link
Member

@mulmat thanks, I've assigned this to you. A word of caution: be aware that the tables wipe out any prefetches set on the view's queryset, so addressing this will likely need work on the column itself.

@mulmat
Copy link
Contributor Author

mulmat commented Apr 29, 2024

@mulmat thanks, I've assigned this to you. A word of caution: be aware that the tables wipe out any prefetches set on the view's queryset, so addressing this will likely need work on the column itself.

Since this in in the api part I think #15886 should be enough? Or did you also discover this to be an issue in the IPAddressListView view? @jeremystretch

@jeremystretch
Copy link
Member

Sorry; I had it in my head that this was for the UI. Disregard my note above!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: needs owner This issue is tentatively accepted pending a volunteer committed to its 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