From 082adb4fd65fa1b28c0d10b306c91aa49dca0b30 Mon Sep 17 00:00:00 2001 From: Stig Lindqvist Date: Thu, 6 Jun 2013 13:43:25 +1200 Subject: [PATCH] NEW: Improve the unittest running time by not truncating tables When clearing tables this will delete all rows instead of truncating it. Benchmarking this change by running the full cms and framework test suit changed improved the running time from 32 minutes to 9 minutes. If truncate functionality is needed for any special cases it should be run as DB::query("TRUNCATE \"TableToTruncate\""); --- code/PostgreSQLDatabase.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index f376035..b4fcedc 100644 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -1365,6 +1365,20 @@ class PostgreSQLDatabase extends SS_Database { return false; } + /** + * Delete all entries from the table instead of truncating it. + * + * This gives a massive speed improvement compared to using TRUNCATE, with + * the caveat that primary keys are not reset etc. + * + * @see DatabaseAdmin::clearAllData() + * + * @param string $table + */ + public function clearTable($table) { + $this->query('DELETE FROM "'.$table.'";'); + } + /** * Return a boolean type-formatted string *