? 259368_2.patch ? 353580-1-axyjo.patch ? 353580-2-axyjo.patch ? current.patch ? multiple_require_once_1.patch ? node-access_0.patch ? node-access_1.patch ? node_access_17.patch ? node_access_18.patch ? node_access_tests_1.patch ? remove_hook_comment_op_3.patch ? remove_hook_comment_op_4.patch ? remove_hook_comment_op_5.patch ? remove_hook_comment_op_6.patch ? remove_hook_comment_op_7.patch ? user_access_unexpect.patch ? user_access_unexpect_works.patch ? user_op_comment.patch ? user_op_comment_1.patch ? modules/node/.node.test.swp ? modules/simpletest/tests/common.info ? modules/simpletest/tests/common.module ? modules/simpletest/tests/l_class_test.patch ? modules/upload/upload_12-24-08.patch ? sites/default/files ? sites/default/settings.php Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.1008 diff -u -p -r1.1008 node.module --- modules/node/node.module 31 Dec 2008 12:02:22 -0000 1.1008 +++ modules/node/node.module 3 Jan 2009 17:04:33 -0000 @@ -2132,15 +2132,25 @@ function node_search_validate($form, &$f * @param $account * Optional, a user object representing the user for whom the operation is to * be performed. Determines access for a user other than the current user. + * @param $reset + * Whether to reset the internal node_access cache. + * * @return * TRUE if the operation may be performed. */ -function node_access($op, $node, $account = NULL) { +function node_access($op, $node, $account = NULL, $reset = NULL) { global $user; + static $count, $rights = array(); if (!$node) { return FALSE; } + + if ($reset) { + $rights = array(); + unset($count); + } + // Convert the node to an object if necessary: if ($op != 'create') { $node = (object)$node; @@ -2149,6 +2159,11 @@ function node_access($op, $node, $accoun if (empty($account)) { $account = $user; } + // Returned cached value if it exists. + if (isset($node->nid) && isset($rights[$account->uid][$node->nid][$op])) { + return $rights[$account->uid][$node->nid][$op]; + } + // If the node is in a restricted format, disallow editing. if ($op == 'update' && !filter_access($node->format)) { return FALSE; @@ -2167,12 +2182,21 @@ function node_access($op, $node, $accoun $base = node_get_types('base', $node); $access = module_invoke($base, 'access', $op, $node, $account); if (!is_null($access)) { + if (isset($node->nid)) { + $rights[$account->uid][$node->nid][$op] = $access; + } return $access; } + // Use $count to avoid looking up access rights if there is only the + // standard Drupal access. + if (!isset($count)) { + $count = db_query('SELECT COUNT(*) FROM {node_access}')->fetchField(); + } + // If the module did not override the access rights, use those set in the // node_access table. - if ($op != 'create' && $node->nid && $node->status) { + if ($count > 1 && $op != 'create' && $node->nid && $node->status) { $grants = array(); foreach (node_access_grants($op, $account) as $realm => $gids) { foreach ($gids as $gid) { @@ -2186,12 +2210,14 @@ function node_access($op, $node, $accoun } $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)); + $result = (db_result(db_query($sql, $node->nid))); + $rights[$account->uid][$node->nid][$op] = $result; + return $result; } // Let authors view their own nodes. if ($op == 'view' && $account->uid == $node->uid && $account->uid != 0) { + $rights[$account->uid][$node->nid][$op] = TRUE; return TRUE; }