2
0
forked from Wavyzz/dolibarr

Perf: Try to optimize speed a little bit

This commit is contained in:
Laurent Destailleur
2010-04-05 19:24:23 +00:00
parent 6935beece2
commit e3ec84d202

View File

@@ -186,7 +186,7 @@ function run_sql($sqlfile,$silent=1,$entity='')
$from='__+MAX_'.$table.'__'; $from='__+MAX_'.$table.'__';
$to='+'.$listofmaxrowid[$table]; $to='+'.$listofmaxrowid[$table];
$newsql=str_replace($from,$to,$newsql); $newsql=str_replace($from,$to,$newsql);
dol_syslog('Admin.lib::run_sql New Request '.($i+1).' sql='.$newsql, LOG_DEBUG); dol_syslog('Admin.lib::run_sql New Request '.($i+1).' (replacing '.$from.' to '.$to.') sql='.$newsql, LOG_DEBUG);
$arraysql[$i]=$newsql; $arraysql[$i]=$newsql;
} }
@@ -200,18 +200,12 @@ function run_sql($sqlfile,$silent=1,$entity='')
{ {
if ($sql) if ($sql)
{ {
$newsql=$sql; $newsql=preg_replace('/__ENTITY__/i',(!empty($entity)?$entity:$conf->entity),$sql);
// Ajout trace sur requete (eventuellement ? commenter si beaucoup de requetes) // Ajout trace sur requete (eventuellement a commenter si beaucoup de requetes)
if (! $silent) print '<tr><td valign="top">'.$langs->trans("Request").' '.($i+1)." sql='".$newsql."'</td></tr>\n"; if (! $silent) print '<tr><td valign="top">'.$langs->trans("Request").' '.($i+1)." sql='".$newsql."'</td></tr>\n";
dol_syslog('Admin.lib::run_sql Request '.($i+1).' sql='.$newsql, LOG_DEBUG); dol_syslog('Admin.lib::run_sql Request '.($i+1).' sql='.$newsql, LOG_DEBUG);
if (preg_match('/insert into ([^\s]+)/i',$newsql,$reg))
{
// It's an insert
$cursorinsert++;
}
// Replace __x__ with rowid of insert nb x // Replace __x__ with rowid of insert nb x
while (preg_match('/__([0-9]+)__/',$newsql,$reg)) while (preg_match('/__([0-9]+)__/',$newsql,$reg))
{ {
@@ -227,23 +221,16 @@ function run_sql($sqlfile,$silent=1,$entity='')
$from='__'.$cursor.'__'; $from='__'.$cursor.'__';
$to=$listofinsertedrowid[$cursor]; $to=$listofinsertedrowid[$cursor];
$newsql=str_replace($from,$to,$newsql); $newsql=str_replace($from,$to,$newsql);
dol_syslog('Admin.lib::run_sql New Request '.($i+1).' sql='.$newsql, LOG_DEBUG); dol_syslog('Admin.lib::run_sql New Request '.($i+1).' (replacing '.$from.' to '.$to.') sql='.$newsql, LOG_DEBUG);
}
// Replace __ENTITY__ with current entity id
while (preg_match('/(__ENTITY__)/i',$newsql,$reg))
{
$from = $reg[1];
$to = (!empty($entity)?$entity:$conf->entity);
$newsql = str_replace($from,$to,$newsql);
dol_syslog('Admin.lib::run_sql New Request '.($i+1).' sql='.$newsql, LOG_DEBUG);
} }
$result=$db->query($newsql); $result=$db->query($newsql);
if ($result) if ($result)
{ {
if (preg_match('/insert into ([^\s]+)/i',$newsql,$reg)) if (preg_replace('/insert into ([^\s]+)/i',$newsql,$reg))
{ {
$cursorinsert++;
// It's an insert // It's an insert
$table=preg_replace('/([^a-zA-Z_]+)/i','',$reg[1]); $table=preg_replace('/([^a-zA-Z_]+)/i','',$reg[1]);
$insertedrowid=$db->last_insert_id($table); $insertedrowid=$db->last_insert_id($table);