Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
17329b16
Commit
17329b16
authored
Sep 28, 2011
by
catch
Browse files
Issue
#6463
by msonnabaum, Garrett Albright, xjm: Add static caching for user_roles().
parent
094f2704
Changes
1
Hide whitespace changes
Inline
Side-by-side
modules/user/user.module
View file @
17329b16
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment