[PR #19993] [MERGED] Fixes #19321: Reduce redundant database queries during bulk creation of devices #15783

Closed
opened 2025-12-30 00:24:02 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/19993
Author: @jeremystretch
Created: 7/31/2025
Status: Merged
Merged: 8/1/2025
Merged by: @jnovinger

Base: mainHead: 19321-bulk-device-imports


📝 Commits (2)

  • 871eae5 Fixes #19321: Reduce redundant database queries during bulk creation of devices
  • f844d82 Add test for test_get_prefetchable_fields

📊 Changes

3 files changed (+57 additions, -2 deletions)

View changed files

📝 netbox/dcim/models/devices.py (+6 -2)
netbox/utilities/prefetch.py (+34 -0)
netbox/utilities/tests/test_prefetch.py (+17 -0)

📄 Description

Fixes: #19321

  • Introduce the get_prefetchable_fields() utility function
  • Call prefetch_related_objects() on newly-created components when instantiating a component template, to prefetch related objects before creating their search & changelog records during post_save

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/19993 **Author:** [@jeremystretch](https://github.com/jeremystretch) **Created:** 7/31/2025 **Status:** ✅ Merged **Merged:** 8/1/2025 **Merged by:** [@jnovinger](https://github.com/jnovinger) **Base:** `main` ← **Head:** `19321-bulk-device-imports` --- ### 📝 Commits (2) - [`871eae5`](https://github.com/netbox-community/netbox/commit/871eae5c4a6cf4373b9f6c05fffa23d90d5e9b74) Fixes #19321: Reduce redundant database queries during bulk creation of devices - [`f844d82`](https://github.com/netbox-community/netbox/commit/f844d820a14462f652db24acfa602f4d90e02cf4) Add test for test_get_prefetchable_fields ### 📊 Changes **3 files changed** (+57 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/models/devices.py` (+6 -2) ➕ `netbox/utilities/prefetch.py` (+34 -0) ➕ `netbox/utilities/tests/test_prefetch.py` (+17 -0) </details> ### 📄 Description ### Fixes: #19321 - Introduce the `get_prefetchable_fields()` utility function - Call `prefetch_related_objects()` on newly-created components when instantiating a component template, to prefetch related objects before creating their search & changelog records during `post_save` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:24:02 +01:00
adam closed this issue 2025-12-30 00:24:03 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15783