From 8fe1aa016117b9c686f4eb41e919681f756740b8 Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Fri, 28 Aug 2009 13:16:54 +0000 Subject: [PATCH] Optimize export speed git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1033 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- adminer/dump.inc.php | 1 - adminer/include/export.inc.php | 29 ++++++++++++++--------------- adminer/include/functions.inc.php | 9 ++------- adminer/select.inc.php | 1 - 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/adminer/dump.inc.php b/adminer/dump.inc.php index 6ce59d7f..6966ab08 100644 --- a/adminer/dump.inc.php +++ b/adminer/dump.inc.php @@ -146,7 +146,6 @@ DROP PROCEDURE adminer_drop; } } } - dump(); exit; } diff --git a/adminer/include/export.inc.php b/adminer/include/export.inc.php index 3bd3e4f3..13f6d635 100644 --- a/adminer/include/export.inc.php +++ b/adminer/include/export.inc.php @@ -1,5 +1,5 @@ query(($select ? $select : "SELECT * FROM " . idf_escape($table))); //! enum and set as numbers, microtime if ($result) { $fields = fields($table); - $length = 0; + $insert = ""; + $buffer = ""; while ($row = $result->fetch_assoc()) { if ($_POST["format"] == "csv") { dump_csv($row); } else { - $insert = "INSERT INTO " . idf_escape($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES"; + if (!$insert) { + $insert = "INSERT INTO " . idf_escape($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES"; + } $row2 = array(); foreach ($row as $key => $val) { $row2[$key] = (isset($val) ? (ereg('int|float|double|decimal', $fields[$key]["type"]) ? $val : $dbh->quote($val)) : "NULL"); //! columns looking like functions @@ -122,23 +125,21 @@ function dump_data($table, $style, $select = "") { dump("$insert ($s) ON DUPLICATE KEY UPDATE " . implode(", ", $set) . ";\n"); } else { $s = "\n($s)"; - if (!$length) { - dump($insert . $s); - $length = strlen($insert) + strlen($s); + if (!$buffer) { + $buffer = $insert . $s; } else { - $length += 1 + strlen($s); // 1 - separator length - if ($length < $max_packet) { - dump(",$s"); + if (strlen($buffer) + 1 + strlen($s) < $max_packet) { // 1 - separator length + $buffer .= ",$s"; } else { - dump(";\n$insert$s"); - $length = strlen($insert) + strlen($s); + dump("$buffer;\n"); + $buffer = $insert . $s; } } } } } - if ($_POST["format"] != "csv" && $style != "INSERT+UPDATE" && $result->num_rows) { - dump(";\n"); + if ($_POST["format"] != "csv" && $style != "INSERT+UPDATE" && $buffer) { + dump("$buffer;\n"); } } } @@ -151,8 +152,6 @@ function dump_headers($identifier, $multi_table = false) { if ($_POST["output"] == "file" || $_POST["compress"]) { header("Content-Disposition: attachment; filename=$filename.$ext" . ($_POST["compress"] == "gz" ? ".gz" : "")); } - ob_flush(); - flush(); return $ext; } diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 6eb7caad..6dd971c4 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -360,14 +360,9 @@ function process_input($field) { } } -function dump($string = null) { // null $string forces sending of buffer - static $buffer = ""; +function dump($string) { if ($_POST["compress"] == "gz") { - $buffer .= $string; - if (!isset($string) || strlen($buffer) > 1e6) { - echo gzencode($buffer); - $buffer = ""; - } + echo gzencode($string); } else { echo $string; } diff --git a/adminer/select.inc.php b/adminer/select.inc.php index 3f7754cf..9bf4882e 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -48,7 +48,6 @@ if ($_POST && !$error) { } dump_data($_GET["select"], "INSERT", implode(" UNION ALL ", $union)); } - dump(); exit; } if (!$adminer->selectEmailProcess($where)) {