re-order access checks for best efficiency

pwolanin - January 22, 2009 - 02:44
Project:Node clone
Version:6.x-1.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:needs review
Description

the checks in this function could probably be re-rodered for better efficiency. We want ot avoid the node_access() calls if at all possible.

function clone_access($node) {
  global $user;
  // Check basic permissions first.
  $access = (user_access('clone node') || ($user->uid && ($node->uid == $user->uid) && user_access('clone own nodes')));
  // Make sure the user can view the original node content.
  $access = $access && node_access('view', $node);
  // Check additional conditions
  $access = $access && (clone_is_permitted($node->type) && filter_access($node->format) && node_access('create', $node->type));
  // Let other modules alter this - for exmple to only allow some users
  // to clone specific nodes or types.
  foreach (module_implements('clone_access_alter') as $module) {
    $function = $module .'_clone_access_alter';
    $function($access, $node);
  }
  return $access;
}

#1

pwolanin - January 22, 2009 - 02:50
Status:active» needs review
AttachmentSize
reorder-checks-362370-1.patch 4.58 KB

#2

pwolanin - January 22, 2009 - 02:51

for 5.x-2.x (untested)

AttachmentSize
reorder-checks-362370-2-D5.patch 1.3 KB
 
 

Drupal is a registered trademark of Dries Buytaert.