From 0ad70eb2d063cab577a559f6c3d28e787ca1dca8 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sun, 17 Mar 2019 06:06:21 +0900 Subject: Make `truncate_tables` to bulk statements Before: ``` (16.4ms) TRUNCATE TABLE `author_addresses` (20.5ms) TRUNCATE TABLE `authors` (19.4ms) TRUNCATE TABLE `posts` ``` After: ``` Truncate Tables (19.5ms) TRUNCATE TABLE `author_addresses`; TRUNCATE TABLE `authors`; TRUNCATE TABLE `posts` ``` --- .../connection_adapters/postgresql/database_statements.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb') diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb index 208934385f..ae7dbd2868 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb @@ -143,12 +143,6 @@ module ActiveRecord end end - def truncate_tables(*table_names) # :nodoc: - unless table_names.empty? - execute "TRUNCATE TABLE #{table_names.map(&method(:quote_table_name)).join(", ")}" - end - end - # Begins a transaction. def begin_db_transaction execute "BEGIN" @@ -170,6 +164,10 @@ module ActiveRecord end private + def build_truncate_statements(*table_names) + "TRUNCATE TABLE #{table_names.map(&method(:quote_table_name)).join(", ")}" + end + # Returns the current ID of a table's sequence. def last_insert_id_result(sequence_name) exec_query("SELECT currval(#{quote(sequence_name)})", "SQL") -- cgit v1.2.3