* Setup/Admin: restoring 10 rows per sql statement to speed up restore

This commit is contained in:
Ralf Becker 2012-06-10 12:38:35 +00:00
parent ec8eedce63
commit c3e0a2ab15
3 changed files with 45 additions and 4 deletions

View File

@ -341,10 +341,11 @@ class db_backup
* @param boolean $convert_to_system_charset=true convert the restored data to the selected system-charset * @param boolean $convert_to_system_charset=true convert the restored data to the selected system-charset
* @param string $filename='' gives the file name which is used in case of a zip archive. * @param string $filename='' gives the file name which is used in case of a zip archive.
* @param boolean $protect_system_config=true should above system_config values be protected (NOT overwritten) * @param boolean $protect_system_config=true should above system_config values be protected (NOT overwritten)
* @param int $insert_n_rows=10 how many rows to insert in one sql statement
* *
* @returns An empty string or an error message in case of failure. * @returns An empty string or an error message in case of failure.
*/ */
function restore($f,$convert_to_system_charset=true,$filename='',$protect_system_config=true) function restore($f,$convert_to_system_charset=true,$filename='',$protect_system_config=true, $insert_n_rows=10)
{ {
@set_time_limit(0); @set_time_limit(0);
ini_set('auto_detect_line_endings',true); ini_set('auto_detect_line_endings',true);
@ -462,6 +463,11 @@ class db_backup
} }
if (substr($line,0,7) == 'table: ') if (substr($line,0,7) == 'table: ')
{ {
if ($rows) // flush pending rows of last table
{
$this->db->insert($table,$rows,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
}
$rows = array();
$table = substr($line,7); $table = substr($line,7);
$cols = self::csv_split($line=fgets($f)); ++$n; $cols = self::csv_split($line=fgets($f)); ++$n;
@ -501,7 +507,19 @@ class db_backup
{ {
$data = translation::convert($data,$charset); $data = translation::convert($data,$charset);
} }
$this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]); if ($insert_n_rows > 1)
{
$rows[] = $data;
if (count($rows) == $insert_n_rows)
{
$this->db->insert($table,$rows,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
$rows = array();
}
}
else
{
$this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
}
} }
else else
{ {
@ -511,6 +529,10 @@ class db_backup
} }
} }
} }
if ($rows) // flush pending rows
{
$this->db->insert($table,$rows,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
}
// updated the sequences, if the DB uses them // updated the sequences, if the DB uses them
foreach($this->schemas as $table => $schema) foreach($this->schemas as $table => $schema)
{ {

View File

@ -1787,7 +1787,25 @@ class egw_db
$table = self::$tablealiases[$table]; $table = self::$tablealiases[$table];
} }
$inputarr = false; $inputarr = false;
if ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB if (isset($data[0]) && is_array($data[0])) // multiple data rows
{
if ($where) throw new egw_exception_wrong_parameter('Can NOT use $where together with multiple data rows in $data!');
$sql = "$cmd INTO $table ";
foreach($data as $k => $d)
{
if (!$k)
{
$sql .= $this->column_data_implode(',',$d,'VALUES',true,$table_def['fd']);
}
else
{
$sql .= ",\n(".$this->column_data_implode(',',$d,false,true,$table_def['fd']).')';
}
}
$sql .= $sql_append;
}
elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB
{ {
$this->Link_ID->Param(false); // reset param-counter $this->Link_ID->Param(false); // reset param-counter
$cols = array_keys($data); $cols = array_keys($data);

View File

@ -186,8 +186,9 @@ if ($_POST['restore'])
if (is_resource($f = $db_backup->fopen_backup($file,true))) if (is_resource($f = $db_backup->fopen_backup($file,true)))
{ {
echo '<p align="center">'.lang('restore started, this might take a few minutes ...')."</p>\n".str_repeat(' ',4096); echo '<p align="center">'.lang('restore started, this might take a few minutes ...')."</p>\n".str_repeat(' ',4096);
$start = time();
$db_backup->restore($f, true, $file); // allways convert to current system charset on restore $db_backup->restore($f, true, $file); // allways convert to current system charset on restore
$setup_tpl->set_var('error_msg',lang("backup '%1' restored",$file)); $setup_tpl->set_var('error_msg',lang("backup '%1' restored",$file).' ('.(time()-$start).' s)');
if ($run_in_egw) if ($run_in_egw)
{ {
// updating the backup // updating the backup