[PR #3916] [CLOSED] Fixes #3377: Recursive power calculation #12696

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/3916
Author: @hSaria
Created: 1/14/2020
Status: Closed

Base: developHead: 3377-recursive-power-calc


📝 Commits (10+)

  • 6eef5ca Fixes #3377: Recursive power calculation
  • 5bb24f3 Missing unit from leg's allocated
  • 7531efc Added tests for recursive power utilization with a loop
  • 80338f4 Merge branch 'develop' into 3377-recursive-power-calc
  • e3aef95 Fixed three-phase available power divide by zero
  • b8693ca Merge branch '3377-recursive-power-calc' of https://github.com/hSaria/netbox into 3377-recursive-power-calc
  • d225f2f No need for the operator
  • 3303f8f Grouped the feed-specific queries into the global one
  • a4dca60 Merge branch 'develop' into 3377-recursive-power-calc
  • 573d7d2 Added #3377 changelog

📊 Changes

6 files changed (+352 additions, -36 deletions)

View changed files

netbox/dcim/migrations/0098_poweroutlet_downstream_powerports.py (+53 -0)
📝 netbox/dcim/models/__init__.py (+10 -12)
📝 netbox/dcim/models/device_components.py (+105 -18)
📝 netbox/dcim/tests/test_models.py (+173 -0)
📝 netbox/templates/dcim/device.html (+10 -5)
📝 netbox/templates/dcim/powerfeed.html (+1 -1)

📄 Description

Fixes: #3377

Calculate the power utilization with the use of a recursive query. It's a single query from the perspective of the ORM (recursion happens in Postgres which is far faster than doing it in the app).

A note regarding the tests: they'll detect a regression in the calculation of a power or if loops are occurring, but if someone makes a change and the loop test fails... well... let's just say it won't "technically" fail as the DB would loop forever. Just wanted to make you aware of that.

I left the outlet count to only local ones (current behaviour). I can change that to include all children if need be.

Thanks for @andrewcleveland for writing the query. Apart from the loop-prevention mechanism that I added from the Postgres docs, it was pretty much ready for use.


🔄 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/3916 **Author:** [@hSaria](https://github.com/hSaria) **Created:** 1/14/2020 **Status:** ❌ Closed **Base:** `develop` ← **Head:** `3377-recursive-power-calc` --- ### 📝 Commits (10+) - [`6eef5ca`](https://github.com/netbox-community/netbox/commit/6eef5cab0322f59ad71c798f7d98a57050b447f5) Fixes #3377: Recursive power calculation - [`5bb24f3`](https://github.com/netbox-community/netbox/commit/5bb24f3a145ce885749335c49955fdafe094ae34) Missing unit from leg's allocated - [`7531efc`](https://github.com/netbox-community/netbox/commit/7531efcfeceb3aa21af4d21970fe45acb41b4d32) Added tests for recursive power utilization with a loop - [`80338f4`](https://github.com/netbox-community/netbox/commit/80338f4fca61beaed4e0d2d915bf6f8d87b66a8d) Merge branch 'develop' into 3377-recursive-power-calc - [`e3aef95`](https://github.com/netbox-community/netbox/commit/e3aef95662c4fd433f6aeefbd09609d6d30a1fe9) Fixed three-phase available power divide by zero - [`b8693ca`](https://github.com/netbox-community/netbox/commit/b8693ca6a22b298dd1937e04a9b117f498d562ae) Merge branch '3377-recursive-power-calc' of https://github.com/hSaria/netbox into 3377-recursive-power-calc - [`d225f2f`](https://github.com/netbox-community/netbox/commit/d225f2ff344ead874a4b3df3d1a145d8ee23d245) No need for the operator - [`3303f8f`](https://github.com/netbox-community/netbox/commit/3303f8fb5906db7e66757f5e15c3a88b6c4874b1) Grouped the feed-specific queries into the global one - [`a4dca60`](https://github.com/netbox-community/netbox/commit/a4dca6077ae10fb7f85b27e842ba0836fd9d3508) Merge branch 'develop' into 3377-recursive-power-calc - [`573d7d2`](https://github.com/netbox-community/netbox/commit/573d7d2123a2ce1a0bba618b2ae6b98bd799535e) Added #3377 changelog ### 📊 Changes **6 files changed** (+352 additions, -36 deletions) <details> <summary>View changed files</summary> ➕ `netbox/dcim/migrations/0098_poweroutlet_downstream_powerports.py` (+53 -0) 📝 `netbox/dcim/models/__init__.py` (+10 -12) 📝 `netbox/dcim/models/device_components.py` (+105 -18) 📝 `netbox/dcim/tests/test_models.py` (+173 -0) 📝 `netbox/templates/dcim/device.html` (+10 -5) 📝 `netbox/templates/dcim/powerfeed.html` (+1 -1) </details> ### 📄 Description ### Fixes: #3377 Calculate the power utilization with the use of a recursive query. It's a single query from the perspective of the ORM (recursion happens in Postgres which is far faster than doing it in the app). A note regarding the tests: they'll detect a regression in the calculation of a power or if loops are occurring, but if someone makes a change and the loop test fails... well... let's just say it won't "technically" fail as the DB would loop forever. Just wanted to make you aware of that. I left the outlet count to only local ones (current behaviour). I can change that to include all children if need be. > Thanks for @andrewcleveland for writing the query. Apart from the loop-prevention mechanism that I added from the [Postgres docs](https://www.postgresql.org/docs/9.6/queries-with.html), it was pretty much ready for use. --- <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:23:06 +01:00
adam closed this issue 2025-12-29 22:23:07 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#12696