From 3f9696aa0f46dbe5671d6961fdb3edb71761ce18 Mon Sep 17 00:00:00 2001 From: Jared Hendrickson Date: Thu, 11 Sep 2025 16:42:31 -0600 Subject: [PATCH] fix(SpecialNetworkField): don't use query to identify interface representation #749 This commit addresses an issue where loading a SpecialNetworkField from its internal format could result in all NetworkInterface objects be loaded each time. This could cause major delays and CPU utilization when reading many objects containing this field, as it would also load all NetworkInterface objects for each instance. Instead of using query to identify an interface's representation value, we know simply rely on the base InterfaceField to handle the conversion and check if anything was actually converted. --- .../local/pkg/RESTAPI/Fields/SpecialNetworkField.inc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Fields/SpecialNetworkField.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Fields/SpecialNetworkField.inc index 3129f7d7e..07c3af67e 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Fields/SpecialNetworkField.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Fields/SpecialNetworkField.inc @@ -307,13 +307,14 @@ class SpecialNetworkField extends InterfaceField { return $representation_value; } - # If the value is a NetworkInterface, obtain its representation value if it's not the ID - $if_query = NetworkInterface::query(id: $internal_value); - if ($this->represented_as !== 'id' and NetworkInterface::query(id: $internal_value)->exists()) { - return $if_query->first()->{$this->represented_as}->value; + # When loading the regular internal value (from InterfaceField), if the value is different from the + # internal value, it means it was an interface that got converted from its internal ID. So return it. + $representation_value = parent::_from_internal($internal_value); + if ($representation_value !== $internal_value) { + return $representation_value; } - # Otherwise, just return the internal value as it is + # Otherwise, just return the internal value as it is (interface ID, alias, IP, subnet, keyword, etc.) return $internal_value; } }