From b707a448a34345cd0a6609b8bd57874f1325a96c Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 18 Mar 2019 00:21:40 +0900 Subject: Tweak `truncate_tables` * Remove redundant `table_names.empty?` * Early return in `truncate_tables` since it is already deeply nested * Move `truncate_tables` out from between `exec_delete` and `exec_update` --- .../abstract/database_statements.rb | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index 6ea85a691b..6aacbe5f88 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -142,23 +142,6 @@ module ActiveRecord exec_query(sql, name, binds) end - # Executes the truncate statement. - def truncate(table_name, name = nil) - execute(build_truncate_statements(table_name), name) - end - - def truncate_tables(*table_names) # :nodoc: - unless table_names.empty? - with_multi_statements do - disable_referential_integrity do - Array(build_truncate_statements(*table_names)).each do |sql| - execute_batch(sql, "Truncate Tables") - end - end - end - end - end - # Executes update +sql+ statement in the context of this connection using # +binds+ as the bind substitutes. +name+ is logged along with # the executed +sql+ statement. @@ -193,6 +176,23 @@ module ActiveRecord exec_delete(sql, name, binds) end + # Executes the truncate statement. + def truncate(table_name, name = nil) + execute(build_truncate_statements(table_name), name) + end + + def truncate_tables(*table_names) # :nodoc: + return if table_names.empty? + + with_multi_statements do + disable_referential_integrity do + Array(build_truncate_statements(*table_names)).each do |sql| + execute_batch(sql, "Truncate Tables") + end + end + end + end + # Runs the given block in a database transaction, and returns the result # of the block. # -- cgit v1.2.3