From a7d43a51cd5b2fdcf3e924a01e2e2227dce07a75 Mon Sep 17 00:00:00 2001 From: andrew morton Date: Fri, 31 Aug 2012 10:38:17 -0400 Subject: [PATCH] Issue #1765664 by drewish: Use drupal_static() for caching in user_relationships_types_load(). --- README.txt | 2 +- .../user_relationship_privatemsg.test | 4 ++-- user_relationships.admin.inc | 2 +- user_relationships.module | 20 +++++++------------- user_relationships.test | 6 +++--- user_relationships_ui/user_relationships_ui.test | 4 ++-- 6 files changed, 16 insertions(+), 22 deletions(-) diff --git a/README.txt b/README.txt index a09d16e..437f614 100644 --- a/README.txt +++ b/README.txt @@ -63,7 +63,7 @@ need to see the documentation in that file for a deeper explanation. Functions ========= user_relationships_type_load($param = array()) - user_relationships_types_load($reset = NULL) + user_relationships_types_load() user_relationships_type_save($rtype) user_relationships_type_delete($rtid) diff --git a/user_relationship_privatemsg/user_relationship_privatemsg.test b/user_relationship_privatemsg/user_relationship_privatemsg.test index a8badb1..32145eb 100644 --- a/user_relationship_privatemsg/user_relationship_privatemsg.test +++ b/user_relationship_privatemsg/user_relationship_privatemsg.test @@ -43,7 +43,7 @@ class UserRelationshipsPrivatemsgRecipientTestCase extends DrupalWebTestCase { user_relationships_type_save((object) $relationship); // Flush permission cache. - user_relationships_types_load(TRUE); + drupal_static_reset('user_relationships_types_load'); $this->checkPermissions(array(), TRUE); $have_permission = 'can have ' . $relationship['name'] . ' relationships'; @@ -149,7 +149,7 @@ class UserRelationshipsPrivatemsgRecipientTestCase extends DrupalWebTestCase { user_relationships_type_save((object) $relationship); // Flush permission cache. - user_relationships_types_load(TRUE); + drupal_static_reset('user_relationships_types_load'); $this->checkPermissions(array(), TRUE); $have_permission = 'can have ' . $relationship['name'] . ' relationships'; diff --git a/user_relationships.admin.inc b/user_relationships.admin.inc index e0505f6..8834d39 100644 --- a/user_relationships.admin.inc +++ b/user_relationships.admin.inc @@ -415,7 +415,7 @@ function user_relationships_admin_type_delete_submit($form, &$form_state) { user_relationships_type_delete($form_state['values']['rtid']); // #371311 force menu rebuild - user_relationships_types_load(TRUE); + drupal_static_reset('user_relationships_types_load'); menu_rebuild(); drupal_set_message(t('Relationship @rel_name has been deleted.', user_relationships_type_translations($relationship_type))); diff --git a/user_relationships.module b/user_relationships.module index e40ed1d..292fa85 100644 --- a/user_relationships.module +++ b/user_relationships.module @@ -384,15 +384,12 @@ function user_relationships_activity_info() { * relationship, such as rtid or name. Attributes must match column names * in the user_relationship_types table. * - * @param $reset - * a boolean that forces a reset of the internal static types list - * * @return * object of the requested relationship type * */ -function user_relationships_type_load($param = array(), $reset = NULL) { - $types = user_relationships_types_load($reset); +function user_relationships_type_load($param = array()) { + $types = user_relationships_types_load(); if (!is_array($param)) { if (isset($types[$param])) { @@ -432,16 +429,13 @@ function user_relationships_type_load($param = array(), $reset = NULL) { /** * Load all relationship types. * - * @param $reset - * A boolean that forces a reset of the internal static types list - * * @return * Array of relationship_type objects */ -function user_relationships_types_load($reset = FALSE) { - static $relationship_types_list = NULL; +function user_relationships_types_load() { + $relationship_types_list = &drupal_static(__FUNCTION__); - if ($reset || !isset($relationship_types_list)) { + if (!isset($relationship_types_list)) { // Clear the cached list, since some relationships may have disappeared. $relationship_types_list = db_query("SELECT * FROM {user_relationship_types}")->fetchAllAssoc('rtid'); @@ -494,7 +488,7 @@ function user_relationships_type_save($rtype) { if (module_exists('i18n_string')) { i18n_string_object_update('user_relationships_type', $rtype); } - user_relationships_types_load(TRUE); + drupal_static_reset('user_relationships_types_load'); menu_rebuild(); } @@ -516,7 +510,7 @@ function user_relationships_type_delete($rtid) { ->execute(); // Clear static cache. - user_relationships_types_load(TRUE); + drupal_static_reset('user_relationships_types_load'); module_invoke_all('user_relationships_type_delete', $rtype); if (module_exists('i18n_string')) { diff --git a/user_relationships.test b/user_relationships.test index 32635a6..496104c 100644 --- a/user_relationships.test +++ b/user_relationships.test @@ -44,7 +44,7 @@ class UserRelationshipsBaseTestCase extends DrupalWebTestCase { } // Flush static cache. - user_relationships_types_load(TRUE); + drupal_static_reset('user_relationships_types_load'); if (in_array('oneway', $create_types)) { $rtype = new StdClass; @@ -104,10 +104,10 @@ class UserRelationshipsBaseTestCase extends DrupalWebTestCase { } // Flush static cache. - user_relationships_types_load(TRUE); + drupal_static_reset('user_relationships_types_load'); // Flush permission cache. - user_relationships_types_load(TRUE); + user_relationships_types_load(); $this->checkPermissions(array(), TRUE); } } diff --git a/user_relationships_ui/user_relationships_ui.test b/user_relationships_ui/user_relationships_ui.test index e8685c8..3dd7b27 100644 --- a/user_relationships_ui/user_relationships_ui.test +++ b/user_relationships_ui/user_relationships_ui.test @@ -65,7 +65,7 @@ class UserRelationshipUserSettings extends DrupalWebTestCase { user_relationships_type_save($rtype); $this->rtypes['approval-oneway'] = $rtype; - user_relationships_types_load(TRUE); + drupal_static_reset('user_relationships_types_load'); // Allow users to auto approve relationships. variable_set('user_relationships_allow_auto_approve', TRUE); @@ -74,7 +74,7 @@ class UserRelationshipUserSettings extends DrupalWebTestCase { variable_set('user_relationship_mailer_send_mail', TRUE); // Flush permission cache. - user_relationships_types_load(TRUE); + drupal_static_reset('user_relationships_types_load'); $this->checkPermissions(array(), TRUE); } -- 1.7.9.6 (Apple Git-31.1)