It looks like you're new here. If you want to get involved, click one of these buttons!
patch -p1 < optimizations.diff
diff U5wBi vtigerCRM-p2/include/database/PearDatabase.php vtigerCRM/include/database/PearDatabase.php
--- vtigerCRM-p2/include/database/PearDatabase.php Mon Jul 18 18:26:00 2005
+++ vtigerCRM/include/database/PearDatabase.php Mon Oct 31 17:43:37 2005
@@ -12,15 +12,16 @@
* All Rights Reserved.
* Contributor(s): ______________________________________.
********************************************************************************/
require_once('include/logging.php');
-include('adodb/adodb.inc.php');
+include_once('adodb/adodb.inc.php');
require_once("adodb/adodb-xmlschema.inc.php");
require_once('vtiger_logger.php');
global $vtlog;
+ if ( !$vtlog )
$vtlog = new vtiger_logger();
class PearDatabase{
var $database = null;
var $dieOnError = false;
@@ -45,15 +46,15 @@
{
require_once('include/logging.php');
$log1 =& LoggerManager::getLogger('VT');
if(is_array($msg))
{
- $log1->fatal("PearDatabse ->".print_r($msg,true));
+ $log1->info("PearDatabse ->".print_r($msg,true));
}
else
{
- $log1->fatal("PearDatabase ->".$msg);
+ $log1->info("PearDatabase ->".$msg);
}
return $msg;
}
function setDieOnError($value){
@@ -164,11 +165,11 @@
$this->println("ADODB error ".$msg."->[".$this->database->ErrorNo()."]".$this->database->ErrorMsg());
die ($msg."ADODB error ".$msg."->".$this->database->ErrorMsg());
}
else
{
- $this->println("ADODB error ".$msg."->[".$this->database->ErrorNo()."]".$this->database->ErrorMsg());
+ $this->println("ADODB error ".$msg."->[".$this->database->ErrorNo()."]".$this->database->ErrorMsg()." (SQL=".$this->sql.")");
}
return false;
}
@@ -203,11 +204,11 @@
$this->connect(false);
}
else
{
// $this->println("checkconnect using old connection");
- $vtlog->logthis('checkconnect using old connection','info');
+ //$vtlog->logthis('checkconnect using old connection','info');
}
}
/* ADODB converted
function query($sql, $dieOnError=false, $msg=''){
@@ -231,12 +232,17 @@
function query($sql, $dieOnError=false, $msg='')
{
global $vtlog;
//$this->println("ADODB query ".$sql);
$vtlog->logthis('query being executed : '.$sql,'debug');
+ $mytime["start"] = $this->microtime_float();
$this->checkConnection();
$result = & $this->database->Execute($sql);
+ $mytime["execute"] = $this->microtime_float();
+ $mytime["total"] = $mytime["execute"]-$mytime["start"];
+ if ( $mytime["total"] > 0.5 )
+ $vtlog->logthis("TIME: sql statement $sql took {$mytime['total']} seconds.","error");
$this->lastmysqlrow = -1;
if(!$result)$this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError);
return $result;
}
@@ -421,17 +427,25 @@
if($result->EOF)
{
//$this->println("ADODB fetch_array return null");
return NULL;
}
- return $this->change_key_case($result->FetchRow());
+ $ret = @ $this->change_key_case($result->FetchRow());
+ if ( !is_array($ret) )
+ {
+ $this->println( "ERROR: SQL (".$this->sql.")" );
+ $this->println( print_r($result,1) );
+ //die;
+ }
+ return $ret;
}
/* ADODB newly added. replacement for mysql_result() */
function query_result(&$result, $row, $col=0)
{
+ if ( !$result ) return;
//$this->println("ADODB query_result r=".$row." c=".$col);
$result->Move($row);
$rowdata = $this->change_key_case($result->FetchRow());
//$this->println($rowdata);
$coldata = $rowdata[$col];
@@ -932,11 +946,15 @@
$this->checkConnection();
$result = & $this->database->MetaTables('TABLES');
$this->println($result);
return $result;
}
-
+function microtime_float()
+{
+ list($usec, $sec) = explode(" ", microtime());
+ return ((float)$usec + (float)$sec);
+}
}
$adb = new PearDatabase();
$adb->connect();
diff U5wBi vtigerCRM-p2/vtiger_logger.php vtigerCRM/vtiger_logger.php
--- vtigerCRM-p2/vtiger_logger.php Tue Jun 28 16:57:00 2005
+++ vtigerCRM/vtiger_logger.php Mon Oct 31 16:41:51 2005
@@ -11,31 +11,33 @@
class vtiger_logger{
var $debug_status;
+ var $log1;
function logthis($msg,$loglevel)
{
if($this->debug_status)
{
require_once('include/logging.php');
- $log1 =& LoggerManager::getLogger('VT');
+
if(is_array($msg))
{
- $log1->$loglevel("Message".print_r($msg,true));
+ $this->log1->$loglevel("Message".print_r($msg,true));
}
else
{
- $log1->$loglevel("Message ->".$msg);
+ $this->log1->$loglevel("Message ->".$msg);
}
return $msg;
}
}
function vtiger_logger()
{
$this->debug_status= true;
+ $this->log1 =& LoggerManager::getLogger('VT');
}
}
?>
diff U5wBi vtigerCRM-p2/modules/Users/UserInfoUtil.php vtigerCRM/modules/Users/UserInfoUtil.php
--- vtigerCRM-p2/modules/Users/UserInfoUtil.php Wed Jul 13 16:58:00 2005
+++ vtigerCRM/modules/Users/UserInfoUtil.php Mon Oct 31 20:14:56 2005
@@ -77,49 +77,58 @@
//echo 'count is ' .count($result);
if($adb->num_rows($result)!=0) $groupname= $adb->query_result($result,0,"groupname");
return $groupname;
}
-function getAllTabsPermission($profileid)
+function loadAllPerms()
{
global $adb,$MAX_TAB_PER;
+ global $persistPermArray;
+
+ $persistPermArray = Array();
+ $profiles = Array();
+ $sql = "select distinct profileid from profile2tab";
+ $result = $adb->query($sql);
+ $num_rows = $adb->num_rows($result);
+ for ( $i=0; $i < $num_rows; $i++ )
+ $profiles[] = $adb->query_result($result,$i,'profileid');
+
+ foreach ( $profiles as $profileid )
+ {
$sql = "select * from profile2tab where profileid=" .$profileid ;
$result = $adb->query($sql);
- $tab_perr_array = Array();
+ $persistPermArray = Array();
if($MAX_TAB_PER !='')
{
- $tab_perr_array = array_fill(0,$MAX_TAB_PER,0);
+ $persistPermArray[$profileid] = array_fill(0,$MAX_TAB_PER,0);
}
$num_rows = $adb->num_rows($result);
for($i=0; $i<$num_rows; $i++)
{
$tabid= $adb->query_result($result,$i,'tabid');
$tab_per= $adb->query_result($result,$i,'permissions');
- $tab_perr_array[$tabid] = $tab_per;
+ $persistPermArray[$profileid][$tabid] = $tab_per;
+ }
+ }
+ $_SESSION['vtPersistPermArray'] = $persistPermArray;
}
- return $tab_perr_array;
+function getAllTabsPermission($profileid)
+{
+ if ( !isset($_SESSION['vtPersistPermArray']) )
+ loadAllPerms();
+ return $_SESSION['vtPersistPermArray'][$profileid];
}
function getTabsPermission($profileid)
{
- global $adb;
- $sql = "select * from profile2tab where profileid=" .$profileid ;
- $result = $adb->query($sql);
- $tab_perr_array = Array();
- $num_rows = $adb->num_rows($result);
- for($i=0; $i<$num_rows; $i++)
- {
- $tabid= $adb->query_result($result,$i,'tabid');
- $tab_per= $adb->query_result($result,$i,'permissions');
- if($tabid != 1 && $tabid != 3 && $tabid != 16 && $tab_id != 15 && $tab_id != 17 && $tab_id != 18 && $tab_id != 19 && $tab_id != 22)
- {
- $tab_perr_array[$tabid] = $tab_per;
- }
- }
+ if ( !isset($_SESSION['vtPersistPermArray']) )
+ loadAllPerms();
+ $tab_perr_array = $_SESSION['vtPersistPermArray'][$profileid];
+ foreach( array(1,3,16,15,17,18,19,22) as $tabid )
+ $tab_perr_array[$tabid] = 0;
return $tab_perr_array;
-
}
function getTabsActionPermission($profileid)
{
global $adb;
Comments
xdebug is in fact a great tool for any big php project. together with kcachegrind or wincachegrind they make a wonderful combo for profilling.
a couple of things though, the tab permissions i don't think it's a good idea to store them in the session. i can create some confusion if someone is changing the permission levels. we could either force a permission reload when they are changed (for all users) or just rework the queries so we cache the whole permissions at once in a static var (i already did this many months ago).
for the failing sql queries i don't think they should be logged as info, fatal should be reserved for really serious events (when the script must halt) but a failing sql query should at least be reported as warning if not as error.
ciao,
ivan
i think you miss my point in failing sql queries: in peardatabase, every message was logged as failing. not info messages. there was no test to determine if the query failed. that was done somewhere else. my log files were filling with peardatabase failure commands on working sql statements.
i'm not altogether happy with the new vtlogger stuff. it seems that it was created to simplify logging, but most new logger entries don't categorize themselves. i think it has led to a certain laxity in logging.
my vtiger crm is now very speed !
great patch mike, thank you.
works fine!
i'm a vtiger newbie. how can i apply your patch to my windows version of vtiger?
run the patch on your suse install and then copy the affected files to your xp install? <!-- s:) --><img src="{smilies_path}/icon_smile.gif" alt=":)" title="smile" /><!-- s:) --> should be the same source code anyway.
ps: works really nice here too!
i patched my suse install but i didn't wrote down the filenames. can i run the patch again?
so those three files are affected on my system.
patching file include/database/peardatabase.php
hunk #1 failed at 12.
hunk #2 failed at 46.
patch: **** malformed patch at line 43: ".$msg."->[".$this->database->errorno()."]".$this->database->errormsg());
i simply copied the correct files from the os x box to the linux box and it seems to work.
sorry i failed to back up the effected files on my linux box so i can't tell you what the problem is/was.