commit a436135e14e5c890351b12fb6e38de109c012513 Author: Joel Pittet Date: Mon Apr 20 08:35:03 2015 -0700 statics diff --git a/pathauto.module b/pathauto.module index e8866af..2bc2fd0 100644 --- a/pathauto.module +++ b/pathauto.module @@ -362,6 +362,16 @@ function pathauto_field_attach_form($entity_type, $entity, &$form, &$form_state, * Implements hook_entity_load(). */ function pathauto_entity_load($entities, $type) { + static $path_auto_entity_types; + // Save the entity types used statically to avoid unnessasary queries later. + if (!isset($path_auto_entity_types)) { + $path_auto_entity_types = db_query("SELECT entity_type FROM {pathauto_state} GROUP BY entity_type")->fetchAllKeyed(0, 0); + } + + // We aren't storing state for this type at the moment. + if (!isset($path_auto_entity_types[$type])) { + return; + } $states = pathauto_entity_state_load_multiple($type, array_keys($entities)); foreach ($states as $id => $state) { if (!isset($entities[$id]->path['pathauto'])) { @@ -453,20 +463,15 @@ function pathauto_entity_state_load($entity_type, $entity_id) { * An array of entity IDs. */ function pathauto_entity_state_load_multiple($entity_type, $entity_ids) { - try { - // filter out entity_ids that are not integers - $entity_ids = array_filter($entity_ids, 'is_numeric'); - // if everything was filtered out, return an empty array - if(empty($entity_ids)) { - return array(); - } - $pathauto_state = db_query("SELECT entity_id, pathauto FROM {pathauto_state} WHERE entity_type = :entity_type AND entity_id IN (:entity_ids)", - array(':entity_type' => $entity_type, ':entity_ids' => $entity_ids))->fetchAllKeyed(); - - return $pathauto_state; - } catch (Exception $ex) { + static $table_exists; + + if (!isset($table_exists)) { + $table_exists = db_table_exists('pathauto_state'); + } + + if (!$table_exists) { if (!defined('MAINTENANCE_MODE')) { - $message = 'The pathauto_state table does not exist, so a default value was provided. Please make sure to run update.php'; + $message = t('The pathauto_state table does not exist, so a default value was provided. Please make sure to run update.php'); drupal_set_message($message, 'warning'); watchdog('pathauto', $message, array(), WATCHDOG_WARNING); } @@ -477,6 +482,17 @@ function pathauto_entity_state_load_multiple($entity_type, $entity_ids) { return $result; } + + // Filter out entity_ids that are not integers. + $entity_ids = array_filter($entity_ids, 'is_numeric'); + // if everything was filtered out, return an empty array + if (empty($entity_ids)) { + return array(); + } + $sql = "SELECT entity_id, pathauto FROM {pathauto_state} WHERE entity_type = :entity_type AND entity_id IN (:entity_ids)"; + $pathauto_state = db_query($sql, array(':entity_type' => $entity_type, ':entity_ids' => $entity_ids))->fetchAllKeyed(); + + return $pathauto_state; } /**