Parcourir la source

'Fine tuning' (well, removed a couple of speed optimizations because I realized the table messages doesn't maintain any kind of order) of the db export tool

Signed-off-by: emanuele <[email protected]>
emanuele il y a 12 ans
Parent
commit
d6c41a9f86

+ 5 - 19
Sources/DbExtra-mysql.php

@@ -254,34 +254,25 @@ function smf_db_list_tables($db = false, $filter = false)
  */
 function smf_db_insert_sql($tableName, $new_table = false)
 {
-	global $smcFunc, $db_prefix, $detected_id;
-	static $start = 0, $num_rows, $fields, $limit, $last_id;
+	global $smcFunc, $db_prefix;
+	static $start = 0, $num_rows, $fields, $limit;
 
 	if ($new_table)
 	{
 		$limit = strstr($tableName, 'log_') !== false ? 500 : 250;
 		$start = 0;
-		$last_id = 0;
 	}
 
 	$data = '';
 	$tableName = str_replace('{db_prefix}', $db_prefix, $tableName);
 
-	if ($tableName != $db_prefix . 'messages' || $tableName != $db_prefix . 'topics')
-		$detected_id = 0;
-
 	// This will be handy...
 	$crlf = "\r\n";
 
-	// This is done this way because retrieve data only with LIMIT will become slower after each query
-	// and for long tables (e.g. {db_prefix}messages) it could be a pain...
-	// Instead using WHERE speeds up thing *a lot* (especially after the first 50'000 records)
 	$result = $smcFunc['db_query']('', '
 		SELECT /*!40001 SQL_NO_CACHE */ *
-		FROM `' . $tableName . '`' .
-		(!empty($last_id) && !empty($detected_id) ? '
-		WHERE ' . $detected_id . ' > ' . $last_id : '') . '
-		LIMIT ' . (empty($last_id) ? $start . ', ' : '') . $limit,
+		FROM `' . $tableName . '`
+		LIMIT ' . $start . ', ' . $limit,
 		array(
 			'security_override' => true,
 		)
@@ -318,8 +309,6 @@ function smf_db_insert_sql($tableName, $new_table = false)
 			else
 				$field_list[] = '\'' . $smcFunc['db_escape_string']($item) . '\'';
 		}
-		if (!empty($detected_id) && isset($row[$detected_id]))
-			$last_id = $row[$detected_id];
 
 		$data .= '(' . implode(', ', $field_list) . ')' . ',' . $crlf . "\t";
 	}
@@ -340,10 +329,9 @@ function smf_db_insert_sql($tableName, $new_table = false)
  */
 function smf_db_table_sql($tableName)
 {
-	global $smcFunc, $db_prefix, $detected_id;
+	global $smcFunc, $db_prefix;
 
 	$tableName = str_replace('{db_prefix}', $db_prefix, $tableName);
-	$detected_id = '';
 
 	// This will be needed...
 	$crlf = "\r\n";
@@ -386,8 +374,6 @@ function smf_db_table_sql($tableName)
 
 		// And now any extra information. (such as auto_increment.)
 		$schema_create .= ($row['Extra'] != '' ? ' ' . $row['Extra'] : '') . ',' . $crlf;
-		if ($row['Extra'] == 'auto_increment')
-			$detected_id = $row['Field'];
 	}
 	$smcFunc['db_free_result']($result);
 

+ 5 - 18
Sources/DbExtra-postgresql.php

@@ -149,34 +149,25 @@ function smf_db_list_tables($db = false, $filter = false)
  */
 function smf_db_insert_sql($tableName, $new_table = false)
 {
-	global $smcFunc, $db_prefix, $detected_id;
-	static $start = 0, $num_rows, $fields, $limit, $last_id;
+	global $smcFunc, $db_prefix;
+	static $start = 0, $num_rows, $fields, $limit;
 
 	if ($new_table)
 	{
 		$limit = strstr($tableName, 'log_') !== false ? 500 : 250;
 		$start = 0;
-		$last_id = 0;
 	}
 
 	$data = '';
 	$tableName = str_replace('{db_prefix}', $db_prefix, $tableName);
 
-	if ($tableName != $db_prefix . 'messages' || $tableName != $db_prefix . 'topics')
-		$detected_id = 0;
-
 	// This will be handy...
 	$crlf = "\r\n";
 
-	// This is done this way because retrieve data only with LIMIT will become slower after each query
-	// and for long tables (e.g. {db_prefix}messages) it could be a pain...
-	// Instead using WHERE speeds up thing *a lot* (especially after the first 50'000 records)
 	$result = $smcFunc['db_query']('', '
 		SELECT *
-		FROM ' . $tableName .
-		(!empty($last_id) && !empty($detected_id) ? '
-		WHERE ' . $detected_id . ' > ' . $last_id : '') . '
-		LIMIT ' . (empty($last_id) ? $start . ', ' : '') . $limit,
+		FROM ' . $tableName . '
+		LIMIT ' . $start . ', ' . $limit,
 		array(
 			'security_override' => true,
 		)
@@ -214,8 +205,6 @@ function smf_db_insert_sql($tableName, $new_table = false)
 			else
 				$field_list[] = '\'' . $smcFunc['db_escape_string']($item) . '\'';
 		}
-		if (!empty($detected_id) && isset($row[$detected_id]))
-			$last_id = $row[$detected_id];
 
 		// 'Insert' the data.
 		$data .= $insert_msg . '(' . implode(', ', $field_list) . ');' . $crlf;
@@ -237,10 +226,9 @@ function smf_db_insert_sql($tableName, $new_table = false)
  */
 function smf_db_table_sql($tableName)
 {
-	global $smcFunc, $db_prefix, $detected_id;
+	global $smcFunc, $db_prefix;
 
 	$tableName = str_replace('{db_prefix}', $db_prefix, $tableName);
-	$detected_id = '';
 
 	// This will be needed...
 	$crlf = "\r\n";
@@ -293,7 +281,6 @@ function smf_db_table_sql($tableName)
 				$smcFunc['db_free_result']($count_req);
 				// Get the right bloody start!
 				$seq_create .= 'CREATE SEQUENCE ' . $matches[1] . ' START WITH ' . ($max_ind + 1) . ';' . $crlf . $crlf;
-				$detected_id = $row['column_name'];
 			}
 		}
 

+ 5 - 17
Sources/DbExtra-sqlite.php

@@ -196,34 +196,25 @@ function smf_db_list_tables($db = false, $filter = false)
  */
 function smf_db_insert_sql($tableName, $new_table = false)
 {
-	global $smcFunc, $db_prefix, $detected_id;
-	static $start = 0, $num_rows, $fields, $limit, $last_id;
+	global $smcFunc, $db_prefix;
+	static $start = 0, $num_rows, $fields, $limit;
 
 	if ($new_table)
 	{
 		$limit = strstr($tableName, 'log_') !== false ? 500 : 250;
 		$start = 0;
-		$last_id = 0;
 	}
 
 	$data = '';
 	$tableName = str_replace('{db_prefix}', $db_prefix, $tableName);
 
-	if ($tableName != $db_prefix . 'messages' || $tableName != $db_prefix . 'topics')
-		$detected_id = 0;
-
 	// This will be handy...
 	$crlf = "\r\n";
 
-	// This is done this way because retrieve data only with LIMIT will become slower after each query
-	// and for long tables (e.g. {db_prefix}messages) it could be a pain...
-	// Instead using WHERE speeds up thing *a lot* (especially after the first 50'000 records)
 	$result = $smcFunc['db_query']('', '
 		SELECT *
-		FROM ' . $tableName .
-		(!empty($last_id) && !empty($detected_id) ? '
-		WHERE ' . $detected_id . ' > ' . $last_id : '') . '
-		LIMIT ' . (empty($last_id) ? $start . ', ' : '') . $limit,
+		FROM ' . $tableName . '
+		LIMIT ' . $start . ', ' . $limit,
 		array(
 			'security_override' => true,
 		)
@@ -267,8 +258,6 @@ function smf_db_insert_sql($tableName, $new_table = false)
 			else
 				$field_list[] = '\'' . $smcFunc['db_escape_string']($item) . '\'';
 		}
-		if (!empty($detected_id) && isset($row[$detected_id]))
-			$last_id = $row[$detected_id];
 
 		// 'Insert' the data.
 		$data .= $insert_msg . '(' . implode(', ', $field_list) . ');' . $crlf;
@@ -290,10 +279,9 @@ function smf_db_insert_sql($tableName, $new_table = false)
  */
 function smf_db_table_sql($tableName)
 {
-	global $smcFunc, $db_prefix, $detected_id;
+	global $smcFunc, $db_prefix;
 
 	$tableName = str_replace('{db_prefix}', $db_prefix, $tableName);
-	$detected_id = '';
 
 	// This will be needed...
 	$crlf = "\r\n";

+ 1 - 1
Sources/ManageMaintenance.php

@@ -169,7 +169,7 @@ function MaintainDatabase()
 	//  * safe_mode enable OR
 	//  * cannot change the execution time OR
 	//  * cannot reset timeout
-	if ($context['safe_mode_enable'] || empty($new_time_limit) || $current_time_limit == $new_time_limit || !function_exists('apache_reset_timeout'))
+	if ($context['safe_mode_enable'] || empty($new_time_limit) || ($current_time_limit == $new_time_limit && !function_exists('apache_reset_timeout')))
 		$context['suggested_method'] = 'use_external_tool';
 	elseif ($zip_limit < $plain_limit && $messages < $zip_limit)
 		$context['suggested_method'] = 'zipped_file';