When you insert a SQL query in your getPermissions function, this will slow down the app dramatically because this function is called by each query. To resolve this problem, it is better to use cached permissions in your /conf/ApplicationDelegate.php or table/table.php.
Procedure
Here is an example :
class tables_mytable {
private $cachedPerms = null;
private function _getCachedPerms($param1, $param2, ..., $paramN){
if ( !isset($this->cachedPerms) ) {
$this->cachedPerms = array();
// do some stuff
$res = mysql_query("select * from foo where bar=1 and param2='".addslashes($param2)."'");
while ( $row = mysql_fetch_assoc($res) ) $this->cachedPerms[$row['fooid']] = $row;
}
return $this->cachedPerms;
}
function getPermissions($record){
// do some stuff
$perms = $this->getCachedPerms($param1, $param2, ..., $paramN);
return $perms;
}
}
Here, getPermissions() will run a db query on its first request, but subsequent requests will just load the cached value.
blog comments powered by Disqus