diff --git a/content_profile.install b/content_profile.install index 2b411ce..a34fcd0 100644 --- a/content_profile.install +++ b/content_profile.install @@ -5,6 +5,13 @@ */ /** + * Implements hook_schema_alter(). + */ +function content_profile_schema_alter(&$schema) { + $schema['node']['indexes']['content_profile'] = array('uid', 'type'); +} + +/** * Implementation of hook_enable(). */ function content_profile_enable() { @@ -39,6 +46,9 @@ function content_profile_install() { $info = _node_type_set_defaults($info); node_type_save((object)$info); } + + $ret = array(); + db_add_index($ret, 'node', 'content_profile', array('uid', 'name')); } /** @@ -78,6 +88,8 @@ function content_profile_uninstall() { variable_del('content_profile_'. $typename); } } + $ret = array(); + db_drop_index($ret, 'node', 'content_profile'); } /** @@ -136,3 +148,12 @@ function content_profile_update_6004() { } return $ret; } + +/** + * Add an index to the {node} table. + */ +function content_profile_update_6005() { + $ret = array(); + db_add_index($ret, 'node', 'content_profile', array('uid', 'type')); + return $ret; +} diff --git a/content_profile.module b/content_profile.module index fb1026d..b345155 100644 --- a/content_profile.module +++ b/content_profile.module @@ -475,14 +475,15 @@ function content_profile_load($type, $uid, $lang = '', $reset = NULL) { static $cache = array(); if (!isset($cache[$type][$uid][$lang]) || $reset) { - $cache[$type][$uid][$lang] = FALSE; - $params = array('type' => $type, 'uid' => $uid); - if ($node = node_load($lang ? $params + array('language' => $lang) : $params, NULL, $reset)) { - $cache[$type][$uid][$lang] = $node->nid; + if (empty($lang)) { + $nid = db_result(db_query("SELECT nid FROM {node} WHERE uid = %d AND type = '%s'", $uid, $type)); } - return $node; + else { + $nid = db_result(db_query("SELECT nid FROM {node} WHERE uid = %d AND type = '%s'", $uid, $type, $lang)); + } + $cache[$type][$uid][$lang] = $nid; } - return !empty($cache[$type][$uid][$lang]) ? node_load($cache[$type][$uid][$lang]) : FALSE; + return !empty($cache[$type][$uid][$lang]) ? node_load($cache[$type][$uid][$lang], NULL, $reset) : FALSE; } /**