[PR #18983] [MERGED] Closes #18980: Optimize update of object data when adding/removing custom fields #15493

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/18983
Author: @jeremystretch
Created: 3/21/2025
Status: Merged
Merged: 3/24/2025
Merged by: @jnovinger

Base: mainHead: 18980-custom-field-bulk-updates


📝 Commits (3)

  • 48c9cc6 Employ native PostgreSQL functions for updating object JSON data when adding/removing custom fields
  • a6384e6 Optimize rename_object_data()
  • 60a4e1f remove_stale_data() should validate model class

📊 Changes

1 file changed (+31 additions, -16 deletions)

View changed files

📝 netbox/extras/models/customfields.py (+31 -16)

📄 Description

Fixes: #18980

  • populate_initial_data() now uses the PostgreSQL-native jsonb_set() function to set initial values on objects when creating a custom field
  • remove_stale_data() now uses native JSON mutation to remove the keys for deleted custom fields
  • rename_object_data() has likewise been optimized to rename custom field keys in object data using jsonb_set()

A quick test using a REST API call adding a custom field to ~11,000 interfaces took 0.543s with this change versus 5.556s in main.


🔄 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/18983 **Author:** [@jeremystretch](https://github.com/jeremystretch) **Created:** 3/21/2025 **Status:** ✅ Merged **Merged:** 3/24/2025 **Merged by:** [@jnovinger](https://github.com/jnovinger) **Base:** `main` ← **Head:** `18980-custom-field-bulk-updates` --- ### 📝 Commits (3) - [`48c9cc6`](https://github.com/netbox-community/netbox/commit/48c9cc6182feb232d071ed58dd61cabd2a12c4dd) Employ native PostgreSQL functions for updating object JSON data when adding/removing custom fields - [`a6384e6`](https://github.com/netbox-community/netbox/commit/a6384e6c9c51df2337d330cee206caee513d43ee) Optimize rename_object_data() - [`60a4e1f`](https://github.com/netbox-community/netbox/commit/60a4e1fd8144f5f5b4ada227852c50073e9cde29) remove_stale_data() should validate model class ### 📊 Changes **1 file changed** (+31 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `netbox/extras/models/customfields.py` (+31 -16) </details> ### 📄 Description ### Fixes: #18980 - `populate_initial_data()` now uses the PostgreSQL-native `jsonb_set()` function to set initial values on objects when creating a custom field - `remove_stale_data()` now uses native JSON mutation to remove the keys for deleted custom fields - `rename_object_data()` has likewise been optimized to rename custom field keys in object data using `jsonb_set()` A quick test using a REST API call adding a custom field to ~11,000 interfaces took 0.543s with this change versus 5.556s in `main`. --- <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:22:17 +01:00
adam closed this issue 2025-12-30 00:22:17 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15493