diff --git a/modules/node/node.module b/modules/node/node.module index 1d88834..90cd878 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1188,6 +1188,7 @@ function node_save($node) { unset($node->original); // Clear the static loading cache. entity_get_controller('node')->resetCache(array($node->nid)); + drupal_static_reset('node_access_grants'); // Ignore slave server temporarily to give time for the // saved node to be propagated to the slave. @@ -3194,17 +3195,25 @@ function node_permissions_get_configured_types() { * arrays of grants for those realms. */ function node_access_grants($op, $account = NULL) { + $grants = &drupal_static(__FUNCTION__, array()); if (!isset($account)) { $account = $GLOBALS['user']; } - // Fetch node access grants from other modules. - $grants = module_invoke_all('node_grants', $account, $op); - // Allow modules to alter the assigned grants. - drupal_alter('node_grants', $grants, $account, $op); + // Grants are unique only per account and per operation on any single request. + $cid = $account->uid . ':' . $op; - return array_merge(array('all' => array(0)), $grants); + if (!isset($grants[$cid])) { + // Fetch node access grants from other modules. + $grants[$cid] = module_invoke_all('node_grants', $account, $op); + // Allow modules to alter the assigned grants. + drupal_alter('node_grants', $grants[$cid], $account, $op); + + $grants[$cid] = array_merge(array('all' => array(0)), $grants[$cid]); + } + + return $grants[$cid]; } /** diff --git a/modules/node/node.test b/modules/node/node.test index e8eb459..6ea900b 100644 --- a/modules/node/node.test +++ b/modules/node/node.test @@ -2331,6 +2331,7 @@ function testNodeQueryAlterOverride() { // Test that the noAccessUser still doesn't have the 'view' // privilege after adding the node_access record. drupal_static_reset('node_access_view_all_nodes'); + drupal_static_reset('node_access_grants'); try { $query = db_select('node', 'mytab') ->fields('mytab'); @@ -2353,6 +2354,7 @@ function testNodeQueryAlterOverride() { $this->drupalLogin($this->noAccessUser2); variable_set('node_test_node_access_all_uid', $this->noAccessUser->uid); drupal_static_reset('node_access_view_all_nodes'); + drupal_static_reset('node_access_grants'); try { $query = db_select('node', 'mytab') ->fields('mytab');