From e3ec84d202f296d0b8638e56bb4e60a722915b38 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 5 Apr 2010 19:24:23 +0000 Subject: [PATCH] Perf: Try to optimize speed a little bit --- htdocs/lib/admin.lib.php | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/htdocs/lib/admin.lib.php b/htdocs/lib/admin.lib.php index 63dcccb3be6..0244438a84d 100644 --- a/htdocs/lib/admin.lib.php +++ b/htdocs/lib/admin.lib.php @@ -186,7 +186,7 @@ function run_sql($sqlfile,$silent=1,$entity='') $from='__+MAX_'.$table.'__'; $to='+'.$listofmaxrowid[$table]; $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; } @@ -200,18 +200,12 @@ function run_sql($sqlfile,$silent=1,$entity='') { 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 ''.$langs->trans("Request").' '.($i+1)." sql='".$newsql."'\n"; 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 while (preg_match('/__([0-9]+)__/',$newsql,$reg)) { @@ -227,23 +221,16 @@ function run_sql($sqlfile,$silent=1,$entity='') $from='__'.$cursor.'__'; $to=$listofinsertedrowid[$cursor]; $newsql=str_replace($from,$to,$newsql); - dol_syslog('Admin.lib::run_sql New Request '.($i+1).' 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); + dol_syslog('Admin.lib::run_sql New Request '.($i+1).' (replacing '.$from.' to '.$to.') sql='.$newsql, LOG_DEBUG); } $result=$db->query($newsql); 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 $table=preg_replace('/([^a-zA-Z_]+)/i','',$reg[1]); $insertedrowid=$db->last_insert_id($table);