From cbfc16f754bfd1a90ad87bb2e0dd12b992817271 Mon Sep 17 00:00:00 2001 From: Marco Antonio Nina Date: Mon, 11 Nov 2013 10:46:22 -0400 Subject: [PATCH] BUG-13342: Performance Issue SOLVED - Al realizar workspace-restore de un backup el tiempo que toma para restaurarlo es demasiado. - Al estar realizando el restore se van ejecuantado los scripts de llenado de datos en la funcion "executeSQLScript" no se hacia un adecuado insert de los registros. - se utiliza la funcion de mysql "START TRANSACTION" y "COMMIT" que son compatibles para MyISAM y InnoDB, y se van insertando los registros "Insert" por lotes. --- workflow/engine/classes/class.wsTools.php | 29 +++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/workflow/engine/classes/class.wsTools.php b/workflow/engine/classes/class.wsTools.php index edd51e76e..ba91be406 100755 --- a/workflow/engine/classes/class.wsTools.php +++ b/workflow/engine/classes/class.wsTools.php @@ -474,7 +474,7 @@ class workspaceTools $RBAC->initRBAC(); $result = $RBAC->verifyPermissions(); if (count($result) > 1) { - foreach($result as $item) { + foreach ($result as $item) { CLI::logging(" $item... \n"); } } else { @@ -1077,7 +1077,6 @@ class workspaceTools . ' --default_character_set utf8' . ' --execute="SOURCE '.$filename.'"'; shell_exec($command); - } else { //If the safe mode of the server is actived try { @@ -1100,6 +1099,7 @@ class workspaceTools $line = $previous . " " . $line; } $previous = null; + // If the current line doesnt end with ; then put this line together // with the next one, thus supporting multi-line statements. if (strrpos($line, ";") != strlen($line) - 1) { @@ -1107,18 +1107,33 @@ class workspaceTools continue; } $line = substr($line, 0, strrpos($line, ";")); + + if (strrpos($line, "INSERT INTO") !== false) { + if ($insert) { + $result = mysql_query("START TRANSACTION"); + $insert = false; + } + $result = mysql_query($line); + continue; + } else { + if (!$insert) { + $result = mysql_query("COMMIT"); + $insert = true; + } + } + $result = mysql_query($line); if ($result === false) { throw new Exception("Error when running script '$filename', line $j, query '$line': " . mysql_error()); } } + if (!$insert) { + $result = mysql_query("COMMIT"); + } } catch (Exception $e) { CLI::logging(CLI::error("Error:" . "There are problems running script '$filename': " . $e)); } - } - - } static public function restoreLegacy($directory) @@ -1268,10 +1283,10 @@ class workspaceTools foreach ($metadata->directories as $dir) { CLI::logging("+> Restoring directory '$dir'\n"); - if(file_exists("$tempDirectory/$dir" . "/ee")) { + if (file_exists("$tempDirectory/$dir" . "/ee")) { G::rm_dir("$tempDirectory/$dir" . "/ee"); } - if(file_exists("$tempDirectory/$dir" . "/plugin.singleton")) { + if (file_exists("$tempDirectory/$dir" . "/plugin.singleton")) { G::rm_dir("$tempDirectory/$dir" . "/plugin.singleton"); } if (!rename("$tempDirectory/$dir", $workspace->path)) {