Index: branches/RC/core/units/custom_data/custom_data_event_handler.php =================================================================== diff -u -N -r9234 -r10459 --- branches/RC/core/units/custom_data/custom_data_event_handler.php (.../custom_data_event_handler.php) (revision 9234) +++ branches/RC/core/units/custom_data/custom_data_event_handler.php (.../custom_data_event_handler.php) (revision 10459) @@ -24,6 +24,8 @@ function scanCustomFields($prefix) { + static $custom_fields = Array (); + if (defined('IS_INSTALL') && IS_INSTALL && !$this->Application->TableFound('CustomField')) { return false; } @@ -39,18 +41,24 @@ return false; } - // get custom field information - $sql = 'SELECT * - FROM '.TABLE_PREFIX.'CustomField - WHERE Type = '.$item_type.' - ORDER BY CustomFieldId'; - $custom_fields = $this->Conn->Query($sql, 'CustomFieldId'); if (!$custom_fields) { - // config doesn't have custom fields - return false; + // query all custom fields at once -> saves 4 sqls queries + $sql = 'SELECT * + FROM '.TABLE_PREFIX.'CustomField'; + $all_custom_fields = $this->Conn->Query($sql, 'CustomFieldId'); + ksort($all_custom_fields); + + foreach ($all_custom_fields as $custom_field_id => $custom_field_data) { + $cf_type = $custom_field_data['Type']; + if (!array_key_exists($cf_type, $custom_fields)) { + $custom_fields[$cf_type] = Array (); + } + + $custom_fields[$cf_type][$custom_field_id] = $custom_field_data; + } } - return $custom_fields; + return array_key_exists($item_type, $custom_fields) ? $custom_fields[$item_type] : false; } /**