Index: units/custom_data/custom_data_event_handler.php =================================================================== --- units/custom_data/custom_data_event_handler.php (revision 13268) +++ units/custom_data/custom_data_event_handler.php (working copy) @@ -55,20 +55,23 @@ return false; } - if (!$custom_fields || (defined('IS_INSTALL') && IS_INSTALL) || (defined('CUSTOM_FIELD_ADDED') && CUSTOM_FIELD_ADDED)) { + $no_caching = (defined('IS_INSTALL') && IS_INSTALL) || (defined('CUSTOM_FIELD_ADDED') && CUSTOM_FIELD_ADDED); + + if (!$custom_fields || $no_caching) { // query all custom fields at once -> saves 4 sqls queries - $cache_key = 'all_custom_fields[%CfSerial%][%ModSerial%]'; - $all_custom_fields = $this->Application->getCache($cache_key, false); + if ($no_caching) { + $all_custom_fields = $this->getCustomFields(); + } + else { + $cache_key = 'all_custom_fields[%CfSerial%][%ModSerial%]'; + $all_custom_fields = $this->Application->getCache($cache_key, false); - if ($all_custom_fields === false) { - $this->Conn->nextQueryCachable = true; - $sql = 'SELECT * - FROM '.TABLE_PREFIX.'CustomField'; - $all_custom_fields = $this->Conn->Query($sql, 'CustomFieldId'); - ksort($all_custom_fields); - - $this->Application->setCache($cache_key, $all_custom_fields); + if ($all_custom_fields === false) { + $this->Conn->nextQueryCachable = true; + $all_custom_fields = $this->getCustomFields(); + $this->Application->setCache($cache_key, $all_custom_fields); + } } foreach ($all_custom_fields as $custom_field_id => $custom_field_data) { @@ -85,6 +88,22 @@ } /** + * Returns sorted list of all custom fields + * + * @return Array + */ + function getCustomFields() + { + $sql = 'SELECT * + FROM '.TABLE_PREFIX.'CustomField'; + $ret = $this->Conn->Query($sql, 'CustomFieldId'); + + ksort($ret); + + return $ret; + } + + /** * Fills cloned cdata config with data from it's parent * * @param kEvent $event