Skip to content

Commit 3f9696a

Browse files
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.
1 parent b1293cc commit 3f9696a

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Fields/SpecialNetworkField.inc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,14 @@ class SpecialNetworkField extends InterfaceField {
307307
return $representation_value;
308308
}
309309

310-
# If the value is a NetworkInterface, obtain its representation value if it's not the ID
311-
$if_query = NetworkInterface::query(id: $internal_value);
312-
if ($this->represented_as !== 'id' and NetworkInterface::query(id: $internal_value)->exists()) {
313-
return $if_query->first()->{$this->represented_as}->value;
310+
# When loading the regular internal value (from InterfaceField), if the value is different from the
311+
# internal value, it means it was an interface that got converted from its internal ID. So return it.
312+
$representation_value = parent::_from_internal($internal_value);
313+
if ($representation_value !== $internal_value) {
314+
return $representation_value;
314315
}
315316

316-
# Otherwise, just return the internal value as it is
317+
# Otherwise, just return the internal value as it is (interface ID, alias, IP, subnet, keyword, etc.)
317318
return $internal_value;
318319
}
319320
}

0 commit comments

Comments
 (0)