Commit 17329b16 authored by catch's avatar catch

Issue #6463 by msonnabaum, Garrett Albright, xjm: Add static caching for user_roles().

parent 094f2704
......@@ -2739,6 +2739,17 @@ function user_mail_tokens(&$replacements, $data, $options) {
* value.
*/
function user_roles($membersonly = FALSE, $permission = NULL) {
$user_roles = &drupal_static(__FUNCTION__);
// Do not cache roles for specific permissions. This data is not requested
// frequently enough to justify the additional memory use.
if (empty($permission)) {
$cid = $membersonly ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
if (isset($user_roles[$cid])) {
return $user_roles[$cid];
}
}
$query = db_select('role', 'r');
$query->addTag('translatable');
$query->fields('r', array('rid', 'name'));
......@@ -2767,6 +2778,11 @@ function user_roles($membersonly = FALSE, $permission = NULL) {
}
}
if (empty($permission)) {
$user_roles[$cid] = $roles;
return $user_roles[$cid];
}
return $roles;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment