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
aba54725
Commit
aba54725
authored
Dec 08, 2005
by
Dries
Browse files
- Patch
#36429
: remove CONCAT() and speed up node_access query.
parent
3ae534a6
Changes
2
Hide whitespace changes
Inline
Side-by-side
modules/node.module
View file @
aba54725
...
...
@@ -2157,14 +2157,19 @@ function node_access($op, $node = NULL, $uid = NULL) {
// If the module did not override the access rights, use those set in the
// node_access table.
if
(
$node
->
nid
&&
$node
->
status
)
{
$sql
=
'SELECT COUNT(*) FROM {node_access} WHERE (nid = 0 OR nid = %d) AND CONCAT(realm, gid) IN ('
;
$grants
=
array
();
foreach
(
node_access_grants
(
$op
,
$uid
)
as
$realm
=>
$gids
)
{
foreach
(
$gids
as
$gid
)
{
$grants
[]
=
"
'"
.
$realm
.
$gid
.
"'
"
;
$grants
[]
=
"
(gid =
$gid
AND realm = '
$realm
')
"
;
}
}
$sql
.
=
implode
(
','
,
$grants
)
.
') AND grant_'
.
$op
.
' >= 1'
;
$grants_sql
=
''
;
if
(
count
(
$grants
))
{
$grants_sql
=
'AND ('
.
implode
(
' OR '
,
$grants
)
.
')'
;
}
$sql
=
"SELECT COUNT(*) FROM
{
node_access
}
WHERE (nid = 0 OR nid = %d)
$grants_sql
AND grant_
$op
>= 1"
;
$result
=
db_query
(
$sql
,
$node
->
nid
);
return
(
db_result
(
$result
));
}
...
...
@@ -2207,14 +2212,19 @@ function _node_access_where_sql($op = 'view', $node_access_alias = 'na', $uid =
return
;
}
$sql
=
$node_access_alias
.
'.grant_'
.
$op
.
' = 1 AND CONCAT('
.
$node_access_alias
.
'.realm, '
.
$node_access_alias
.
'.gid) IN ('
;
$grants
=
array
();
foreach
(
node_access_grants
(
$op
,
$uid
)
as
$realm
=>
$gids
)
{
foreach
(
$gids
as
$gid
)
{
$grants
[]
=
"
'"
.
$realm
.
$gid
.
"'
"
;
$grants
[]
=
"
(
$node_access_alias
.gid =
$gid
AND
$node_access_alias
.realm = '
$realm
')
"
;
}
}
$sql
.
=
implode
(
','
,
$grants
)
.
')'
;
$grants_sql
=
''
;
if
(
count
(
$grants
))
{
$grants_sql
=
'AND ('
.
implode
(
' OR '
,
$grants
)
.
')'
;
}
$sql
=
"
$node_access_alias
.grant_
$op
>= 1
$grants_sql
"
;
return
$sql
;
}
...
...
@@ -2253,14 +2263,19 @@ function node_access_view_all_nodes() {
static
$access
;
if
(
!
isset
(
$access
))
{
$sql
=
'SELECT COUNT(*) FROM {node_access} WHERE nid = 0 AND CONCAT(realm, gid) IN ('
;
$grants
=
array
();
foreach
(
node_access_grants
(
'view'
)
as
$realm
=>
$gids
)
{
foreach
(
$gids
as
$gid
)
{
$grants
[]
=
"
'"
.
$realm
.
$gid
.
"'
"
;
$grants
[]
=
"
(gid =
$gid
AND realm = '
$realm
')
"
;
}
}
$sql
.
=
implode
(
','
,
$grants
)
.
') AND grant_view = 1'
;
$grants_sql
=
''
;
if
(
count
(
$grants
))
{
$grants_sql
=
'AND ('
.
implode
(
' OR '
,
$grants
)
.
')'
;
}
$sql
=
"SELECT COUNT(*) FROM
{
node_access
}
WHERE nid = 0
$grants_sql
AND grant_view >= 1"
;
$result
=
db_query
(
$sql
);
$access
=
db_result
(
$result
);
}
...
...
modules/node/node.module
View file @
aba54725
...
...
@@ -2157,14 +2157,19 @@ function node_access($op, $node = NULL, $uid = NULL) {
// If the module did not override the access rights, use those set in the
// node_access table.
if
(
$node
->
nid
&&
$node
->
status
)
{
$sql
=
'SELECT COUNT(*) FROM {node_access} WHERE (nid = 0 OR nid = %d) AND CONCAT(realm, gid) IN ('
;
$grants
=
array
();
foreach
(
node_access_grants
(
$op
,
$uid
)
as
$realm
=>
$gids
)
{
foreach
(
$gids
as
$gid
)
{
$grants
[]
=
"
'"
.
$realm
.
$gid
.
"'
"
;
$grants
[]
=
"
(gid =
$gid
AND realm = '
$realm
')
"
;
}
}
$sql
.
=
implode
(
','
,
$grants
)
.
') AND grant_'
.
$op
.
' >= 1'
;
$grants_sql
=
''
;
if
(
count
(
$grants
))
{
$grants_sql
=
'AND ('
.
implode
(
' OR '
,
$grants
)
.
')'
;
}
$sql
=
"SELECT COUNT(*) FROM
{
node_access
}
WHERE (nid = 0 OR nid = %d)
$grants_sql
AND grant_
$op
>= 1"
;
$result
=
db_query
(
$sql
,
$node
->
nid
);
return
(
db_result
(
$result
));
}
...
...
@@ -2207,14 +2212,19 @@ function _node_access_where_sql($op = 'view', $node_access_alias = 'na', $uid =
return
;
}
$sql
=
$node_access_alias
.
'.grant_'
.
$op
.
' = 1 AND CONCAT('
.
$node_access_alias
.
'.realm, '
.
$node_access_alias
.
'.gid) IN ('
;
$grants
=
array
();
foreach
(
node_access_grants
(
$op
,
$uid
)
as
$realm
=>
$gids
)
{
foreach
(
$gids
as
$gid
)
{
$grants
[]
=
"
'"
.
$realm
.
$gid
.
"'
"
;
$grants
[]
=
"
(
$node_access_alias
.gid =
$gid
AND
$node_access_alias
.realm = '
$realm
')
"
;
}
}
$sql
.
=
implode
(
','
,
$grants
)
.
')'
;
$grants_sql
=
''
;
if
(
count
(
$grants
))
{
$grants_sql
=
'AND ('
.
implode
(
' OR '
,
$grants
)
.
')'
;
}
$sql
=
"
$node_access_alias
.grant_
$op
>= 1
$grants_sql
"
;
return
$sql
;
}
...
...
@@ -2253,14 +2263,19 @@ function node_access_view_all_nodes() {
static
$access
;
if
(
!
isset
(
$access
))
{
$sql
=
'SELECT COUNT(*) FROM {node_access} WHERE nid = 0 AND CONCAT(realm, gid) IN ('
;
$grants
=
array
();
foreach
(
node_access_grants
(
'view'
)
as
$realm
=>
$gids
)
{
foreach
(
$gids
as
$gid
)
{
$grants
[]
=
"
'"
.
$realm
.
$gid
.
"'
"
;
$grants
[]
=
"
(gid =
$gid
AND realm = '
$realm
')
"
;
}
}
$sql
.
=
implode
(
','
,
$grants
)
.
') AND grant_view = 1'
;
$grants_sql
=
''
;
if
(
count
(
$grants
))
{
$grants_sql
=
'AND ('
.
implode
(
' OR '
,
$grants
)
.
')'
;
}
$sql
=
"SELECT COUNT(*) FROM
{
node_access
}
WHERE nid = 0
$grants_sql
AND grant_view >= 1"
;
$result
=
db_query
(
$sql
);
$access
=
db_result
(
$result
);
}
...
...
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