Ignore:
Timestamp:
Jan 18, 2012, 10:21:43 AM (13 years ago)
Author:
chronos
Message:
  • Upraveno: Zrychlení kontroly uživatelských oprávnění pro opakované kontroly se stejnými podmínkami.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/User/User.php

    r347 r356  
    3434  var $AnonymousUserId = 98;
    3535  var $OnlineStateTimeout = 600; // in seconds
     36  var $PermissionCache = array();
    3637
    3738  function __construct($Database, $System)
     
    226227  function CheckPermission($Module, $Operation, $ItemType = '', $ItemIndex = 0)
    227228  {
    228         $DbResult = $this->Database->select('PermissionOperation', 'Id', '`Module`="'.$Module.'" AND `Item`="'.$ItemType.'" AND `ItemId`='.$ItemIndex.' AND `Operation`="'.$Operation.'"');
    229     if($DbResult->num_rows > 0)
    230     {
    231       $DbRow = $DbResult->fetch_array();
    232       $OperationId = $DbRow['Id'];
    233 
     229    // First try to check cache
     230    if(in_array(array($Module, $Operation, $ItemType, $ItemType), $this->PermissionCache))
     231    {
     232      $OperationId = array_search(array($Module, $Operation, $ItemType, $ItemType), $this->PermissionCache);
     233      $PermissionExists = is_numeric($OperationId);
     234    } else
     235    {   
     236      // If no permission combination exists in cache, do new check of database items
     237      $DbResult = $this->Database->select('PermissionOperation', 'Id', '`Module`="'.$Module.'" AND `Item`="'.$ItemType.'" AND `ItemId`='.$ItemIndex.' AND `Operation`="'.$Operation.'"');
     238      if($DbResult->num_rows > 0)
     239      {
     240        $DbRow = $DbResult->fetch_array();
     241        $OperationId = $DbRow['Id'];
     242        $this->PermissionCache[$DbRow['Id']] = array($Module, $Operation, $ItemType, $ItemType);       
     243        $PermissionExists = true;
     244      } else
     245      {         
     246        $this->PermissionCache[$DbRow['Id'].'_'] = array($Module, $Operation, $ItemType, $ItemType);       
     247        $PermissionExists = false;
     248      }
     249    }
     250   
     251    if($PermissionExists)
     252    {
    234253      // Check user-operation relation
    235254      $DbResult = $this->Database->select('PermissionUserAssignment', '*', '`User`="'.$this->User['Id'].'" AND `GroupOrOperation`="'.$OperationId.'" AND `Type`="Operation"');
     
    240259      while($DbRow = $DbResult->fetch_array())
    241260      {
    242          if($this->CheckGroupPermission($DbRow['GroupOrOperation'], $OperationId) == true) return(true);
     261       if($this->CheckGroupPermission($DbRow['GroupOrOperation'], $OperationId) == true) return(true);
    243262      }
    244263      return(false);
Note: See TracChangeset for help on using the changeset viewer.