[PR #6488] [MERGED] Closes #6087: Cache prefix depth & children count #13135

Closed
opened 2025-12-29 22:25:35 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/6488
Author: @jeremystretch
Created: 5/26/2021
Status: Merged
Merged: 5/28/2021
Merged by: @jeremystretch

Base: developHead: 6087-prefix-depth-children


📝 Commits (7)

📊 Changes

16 files changed (+606 additions, -104 deletions)

View changed files

📝 netbox/ipam/filtersets.py (+6 -0)
netbox/ipam/management/__init__.py (+0 -0)
netbox/ipam/management/commands/__init__.py (+0 -0)
netbox/ipam/management/commands/rebuild_prefixes.py (+27 -0)
netbox/ipam/migrations/0047_prefix_depth_children.py (+21 -0)
netbox/ipam/migrations/0048_prefix_populate_depth_children.py (+46 -0)
📝 netbox/ipam/models/ip.py (+45 -0)
📝 netbox/ipam/querysets.py (+19 -14)
📝 netbox/ipam/signals.py (+45 -2)
📝 netbox/ipam/tables.py (+16 -2)
📝 netbox/ipam/tests/test_filtersets.py (+14 -1)
📝 netbox/ipam/tests/test_models.py (+278 -80)
📝 netbox/ipam/utils.py (+60 -0)
📝 netbox/ipam/views.py (+4 -4)
📝 netbox/templates/ipam/prefix_list.html (+20 -0)
📝 netbox/utilities/tables.py (+5 -1)

📄 Description

Fixes: #6087

  • Ditch annotate_tree() PrefixQueryset method; replace with optional annotate_hierarchy()
  • Add depth and children fields on ipam.Prefix to cache depth and child counts
  • Add a second migration to efficiently update these values for existing deployments
  • Introduce signal receivers to automatically update these values on post_save and post_delete
  • Add get_parents() and get_children() convenience methods on ipam.Prefix

TODO

  • Management command to manually rebuild the prefix hierarchy
  • Extend depth and children query filters

🔄 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/6488 **Author:** [@jeremystretch](https://github.com/jeremystretch) **Created:** 5/26/2021 **Status:** ✅ Merged **Merged:** 5/28/2021 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `6087-prefix-depth-children` --- ### 📝 Commits (7) - [`da558de`](https://github.com/netbox-community/netbox/commit/da558de76913caec478835a84cf7ff71e2d61be7) Initial work on #6087 - [`34e673f`](https://github.com/netbox-community/netbox/commit/34e673f7d619445d1746a52f422b41aa7c6268f4) Introduce rebuild_prefixes management command - [`8401777`](https://github.com/netbox-community/netbox/commit/84017776ecdc9f9f69b36fbb7947da36a93f9799) Fix handling of duplicate prefixes - [`103730a`](https://github.com/netbox-community/netbox/commit/103730a64243d3475975d6cf1e1f212c546db579) Extend depth & children filters - [`d34b9ee`](https://github.com/netbox-community/netbox/commit/d34b9ee00e20b9f707febea6e24a2786d2b1e49f) Add max depth selector - [`88aa3a4`](https://github.com/netbox-community/netbox/commit/88aa3a4e196e8dfe4444fbccd43a184ce4088969) Specify batch size for bulk_update() - [`5cb5f9a`](https://github.com/netbox-community/netbox/commit/5cb5f9a9637528400727e44785c506db9d9a8dee) Linkify prefix children count ### 📊 Changes **16 files changed** (+606 additions, -104 deletions) <details> <summary>View changed files</summary> 📝 `netbox/ipam/filtersets.py` (+6 -0) ➕ `netbox/ipam/management/__init__.py` (+0 -0) ➕ `netbox/ipam/management/commands/__init__.py` (+0 -0) ➕ `netbox/ipam/management/commands/rebuild_prefixes.py` (+27 -0) ➕ `netbox/ipam/migrations/0047_prefix_depth_children.py` (+21 -0) ➕ `netbox/ipam/migrations/0048_prefix_populate_depth_children.py` (+46 -0) 📝 `netbox/ipam/models/ip.py` (+45 -0) 📝 `netbox/ipam/querysets.py` (+19 -14) 📝 `netbox/ipam/signals.py` (+45 -2) 📝 `netbox/ipam/tables.py` (+16 -2) 📝 `netbox/ipam/tests/test_filtersets.py` (+14 -1) 📝 `netbox/ipam/tests/test_models.py` (+278 -80) 📝 `netbox/ipam/utils.py` (+60 -0) 📝 `netbox/ipam/views.py` (+4 -4) 📝 `netbox/templates/ipam/prefix_list.html` (+20 -0) 📝 `netbox/utilities/tables.py` (+5 -1) </details> ### 📄 Description ### Fixes: #6087 - Ditch `annotate_tree()` PrefixQueryset method; replace with **optional** `annotate_hierarchy()` - Add `depth` and `children` fields on ipam.Prefix to cache depth and child counts - Add a second migration to efficiently update these values for existing deployments - Introduce signal receivers to automatically update these values on `post_save` and `post_delete` - Add `get_parents()` and `get_children()` convenience methods on ipam.Prefix #### TODO - [x] Management command to manually rebuild the prefix hierarchy - [x] Extend `depth` and `children` query filters --- <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-29 22:25:35 +01:00
adam closed this issue 2025-12-29 22:25:35 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#13135