Skip to content

Commit ce760dd

Browse files
fix(ForeignModelField): don't query if target and local fields are the same #749
This addresses an issue where the ForeignModelField could unnecessarily make query when the target and local field names are the same. In large rulesets this can result in a timeout.
1 parent 7f49b48 commit ce760dd

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ class ForeignModelField extends Field {
217217
* @return mixed The field value in its representation form.
218218
*/
219219
protected function _from_internal(mixed $internal_value): mixed {
220+
# If the model_field_internal, and the model_field are the same, return the internal value as-is.
221+
if ($this->model_field_internal === $this->model_field) {
222+
return $internal_value;
223+
}
224+
220225
# Ensure the internal field value is converted to its representation value before querying
221226
if ($this->model_field_internal !== 'id') {
222227
$internal_value = $this->models[0]->{$this->model_field_internal}->_from_internal($internal_value);

0 commit comments

Comments
 (0)